mindspore.Tensor.new_zeros

Tensor.new_zeros(size, *, dtype=None)[source]

Return a tensor of size filled with zeros.

Parameters

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

Keyword Arguments

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 not an int, list or tuple of integers.

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.]]