mindspore.Tensor.new_zeros

Tensor.new_zeros(size, dtype=None) Tensor

Return a tensor of size filled with zeros.

Parameters
  • size (Union[int, tuple(int), list(int)]) – An int, list or tuple of integers defining the output shape.

  • dtype (mindspore.dtype, optional) – The desired dtype of the output tensor. If None, the returned tensor has the same dtype as self. Default: None.

Outputs:

Tensor, the shape and dtype is defined above and filled with zeros.

Raises
  • TypeError – If size is neither an int nor a tuple/list of int.

  • TypeError – If dtype is not a MindSpore dtype.

  • ValueError – If size contains negative values.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import Tensor
>>> x = Tensor([1, 2, 3, 4], mindspore.int32)
>>> output = x.new_zeros((2, 3))
>>> print(output)
[[0 0 0]
 [0 0 0]]