zeros¶
-
paddle.fluid.layers.
zeros
(shape, dtype, force_cpu=False)[source] The OP creates a tensor of specified
shape
anddtype
, and fills it with 0. Itsstop_gradient
will be set to True to stop gradient computation.- Parameters
shape (tuple|list) – Shape of output tensor.
dtype (np.dtype|core.VarDesc.VarType|str) – Data type of output tensor, it supports bool, float16, float32, float64, int32 and int64.
force_cpu (bool, optional) – Whether force to store the output tensor in CPU memory. If
force_cpu
is False, the output tensor will be stored in running device memory. Default: False.
- Returns
A tensor of data type
dtype
with shapeshape
and all elements set to 0.- Return type
Variable
Examples
import paddle.fluid as fluid data = fluid.layers.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]]