zeros¶
- paddle. zeros ( shape, dtype=None, name=None ) [source]
-
Creates a tensor of specified
shape
anddtype
, and fills it with 0.- Parameters
-
shape (tuple|list|Tensor) – Shape of the Tensor to be created. The data type is
int32
orint64
. Ifshape
is a list or tuple, each element of it should be integer or 0-D Tensor with shape []. Ifshape
is an Tensor, it should be an 1-D Tensor which represents a list.dtype (np.dtype|str, optional) – Data type of output Tensor, it supports bool, float16, float32, float64, int32 and int64. Default: if None, the date type is float32.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
- Returns
-
A tensor of data type
dtype
with shapeshape
and all elements set to 0. - Return type
-
Tensor
Examples
import paddle # shape is a list/tuple data1 = paddle.zeros(shape=[3, 2]) # [[0. 0.] # [0. 0.] # [0. 0.]] # shape is a Tensor shape = paddle.to_tensor([3, 2]) data2 = paddle.zeros(shape=shape) # [[0. 0.] # [0. 0.] # [0. 0.]] # shape is a Tensor List shape = [paddle.to_tensor(3), paddle.to_tensor(2)] data3 = paddle.zeros(shape=shape) # [[0. 0.] # [0. 0.] # [0. 0.]]