mindspore.mint.empty_like
- 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) – 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. DefaultNone.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 = None, the value set bymindspore.set_device()will be used. DefaultNone.pin_memory (bool, optional) – If set pin_memory to True, the tensor will be allocated in pinned memory, and device should be
"cpu"or"CPU". DefaultFalse.
- 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.]]