mindspore.Tensor.new_empty
- Tensor.new_empty(size, *, dtype=None, device=None) Tensor[source]
Returns an uninitialized Tensor. Its shape is specified by size, its dtype is specified by dtype and its device is specified by device.
- Parameters
size (Union[tuple[int], list[int], int]) – The specified shape of output tensor. Only positive integer or tuple or list containing positive integers are allowed.
- Keyword Arguments
dtype (
mindspore.dtype, optional) – The specified dtype of the output tensor. If dtype = None, the tensor will have the same dtype as self. 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.
- Returns
Tensor, whose shape, dtype and device are defined by input but with uninitialized data (May be a random value).
- Raises
TypeError – If size is neither an int nor a tuple or list of int.
- Supported Platforms:
AscendCPU
Examples
>>> import mindspore >>> from mindspore import Tensor >>> x = Tensor([[1, 2, 3], [4, 5, 6]]) >>> output1 = x.new_empty((2, 3)) >>> print(output1) [[0 0 0] [0 0 0]] >>> output2 = x.new_empty((2, 3), dtype=mindspore.float64) >>> print(output2) [[0. 0. 0.] [0. 0. 0.]]