mindspore.Tensor.new_zeros

View Source On Gitee
Tensor.new_zeros(size, dtype=None)[source]

Return a tensor of size filled with zeros.

Warning

For argument size, Tensor type input will be deprecated in the future version.

Parameters
  • size (Union[int, tuple, list, Tensor]) – 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 thesame dtype as self. Default: None.

Returns

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

Raises

TypeError – If size is neither an int nor an tuple/list/Tensor of int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor
>>> x = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> output = x.new_zeros((2, 2))
>>> print(output)
[[0. 0.]
 [0. 0.]]