mindspore.mint.zeros_like

mindspore.mint.zeros_like(input, *, dtype=None)[source]

Creates a tensor filled with 0, with the same size as input. Its data type is determined by the given dtype.

If dtype = None, the tensor will have the same dtype as input input.

Parameters

input (Tensor) – Tensor of any dimension.

Keyword Arguments

dtype (mindspore.dtype, optional) – The specified dtype of the output tensor. If dtype is None , the dtype of the input tensor will be used. Default: None .

Returns

Tensor, filled with 0.

Raises

TypeError – If dtype is not a MindSpore dtype.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> x = Tensor(np.arange(4).reshape(2, 2))
>>> output = mint.zeros_like(x, dtype=mindspore.float32)
>>> print(output)
[[0. 0.]
 [0. 0.]]