_ones_like
ones_like
¶
Generate ones shaped like tensor
with a specified dtype
.
This method can be used with Numpy data:
n = np.array([[0,1],[2,3]])
b = fe.backend.ones_like(n) # [[1, 1], [1, 1]]
b = fe.backend.ones_like(n, dtype="float32") # [[1.0, 1.0], [1.0, 1.0]]
This method can be used with TensorFlow tensors:
t = tf.constant([[0,1],[2,3]])
b = fe.backend.ones_like(t) # [[1, 1], [1, 1]]
b = fe.backend.ones_like(t, dtype="float32") # [[1.0, 1.0], [1.0, 1.0]]
This method can be used with PyTorch tensors:
p = torch.tensor([[0,1],[2,3]])
b = fe.backend.ones_like(p) # [[1, 1], [1, 1]]
b = fe.backend.ones_like(p, dtype="float32") # [[1.0, 1.0], [1.0, 1.0]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
Tensor
|
The tensor whose shape will be copied. |
required |
dtype |
Union[None, str]
|
The data type to be used when generating the resulting tensor. If None then the |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
A tensor of ones with the same shape as |
Raises:
Type | Description |
---|---|
ValueError
|
If |