mindspore.mint.empty_like

mindspore.mint.empty_like(input, *, dtype=None, device=None)[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. Support CPU and Ascend. If device = None, the tensor will have the same device as input input and if the device of the input tensor is not defined, 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.]]