mindspore.mint.empty

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

Creates a tensor with uninitialized data, whose shape, dtype and device are described by the argument size, dtype and device respectively.

Warning

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

Parameters

size (Union[tuple[int], list[int], int]) – The specified shape of output tensor. Can be variable numbers of positive integers or tuple or list containing positive integers.

Keyword Arguments
  • dtype (mindspore.dtype, optional) – The specified type of output tensor. If dtype is None , mindspore.float32 will be used. 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, mindspore.context.device_target will be used. Default None.

Returns

Tensor, whose shape, dtype and device are defined by input.

Raises

TypeError – If size is neither an int nor a tuple or list of int.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import mint
>>> output = mint.empty((2, 3), dtype=mindspore.float32)
>>> print(output)
[[0. 0. 0.]
 [0. 0. 0.]]