mindspore.numpy.asarray(a, dtype=None)[source]

Converts the input to tensor.

This function converts tensors from an array-like object.

  • a (Union[int, float, bool, list, tuple, Tensor]) – Input data, in any form that can be converted to a Tensor. This includes Tensor, list, tuple and numbers.

  • dtype (Union[mindspore.dtype, str], optional) – Designated tensor dtype, can be in format of np.int32, or ‘int32’. If dtype is None, the data type of the new tensor will be inferred from obj. Default is None.


Tensor, generated tensor with the specified dtype.

  • TypeError – If input arguments have types not specified above.

  • ValueError – If input a has different sizes at different dimensions.

Supported Platforms:

Ascend GPU CPU


>>> import mindspore.numpy as np
>>> print(np.asarray([1,2,3]))
[1 2 3]