mindspore.mint.empty_like

View Source On Gitee
mindspore.mint.empty_like(input, *, dtype=None, device=None) Tensor[source]

Returns an uninitialized Tensor with the same shape as the input. Its dtype is specified by dtype and its device is specified by device.

Warning

This is an experimental API that is subject to change or deletion.

Parameters

input (Tensor) – Tensor of any dimension.

Keyword Arguments
  • dtype (mindspore.dtype, optional) – The specified dtype of the output tensor. If dtype = None, the tensor will have the same dtype as input input. Default None.

  • device (string, optional) – The specified device of the output tensor. In PyNative mode, "Ascend", "npu", "cpu" and "CPU" are supported. In graph mode O0, "Ascend" and "npu" are supported. If device = None, the value set by mindspore.set_device() will be used. Default None.

Returns

Tensor, has the same shape, type and device as input but with uninitialized data (May be a random value).

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import mint, Tensor
>>> x = Tensor([[1, 2, 3], [4, 5, 6]])
>>> output1 = mint.empty_like(x)
>>> print(output1)
[[0 0 0]
 [0 0 0]]
>>> output2 = mint.empty_like(x, dtype=mindspore.float64)
>>> print(output2)
[[0. 0. 0.]
 [0. 0. 0.]]