mindspore.ops.zeros_like

View Source On Gitee
mindspore.ops.zeros_like(input, *, dtype=None)[source]

Creates a tensor filled with 0, with the same size as input, and 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 GPU CPU

Examples

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