_zeros_like
zeros_like
¶
Generate zeros 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.zeros_like(n) # [[0, 0], [0, 0]]
b = fe.backend.zeros_like(n, dtype="float32") # [[0.0, 0.0], [0.0, 0.0]]
This method can be used with TensorFlow tensors:
t = tf.constant([[0,1],[2,3]])
b = fe.backend.zeros_like(t) # [[0, 0], [0, 0]]
b = fe.backend.zeros_like(t, dtype="float32") # [[0.0, 0.0], [0.0, 0.0]]
This method can be used with PyTorch tensors:
p = torch.tensor([[0,1],[2,3]])
b = fe.backend.zeros_like(p) # [[0, 0], [0, 0]]
b = fe.backend.zeros_like(p, dtype="float32") # [[0.0, 0.0], [0.0, 0.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 zeros with the same shape as |
Raises:
Type | Description |
---|---|
ValueError
|
If |