mindspore.mint.empty_like

View Source On AtomGit
mindspore.mint.empty_like(input, *, dtype=None, device=None, pin_memory=False) 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. If pin_memory is True, the tensor will be allocated in pinned memory.

Parameters

input (Tensor) – The tensor of any dimension.

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

  • device (str, 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 is None, the value set by mindspore.set_device() will be used. Default None.

  • pin_memory (bool, optional) – If set to True, the tensor will be allocated in pinned memory, and device should be "cpu" or "CPU" . Default False.

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.

  • RuntimeError – If pin_memory is True, and device is neither "cpu" nor "CPU" .

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