mindspore.numpy.asarray
- mindspore.numpy.asarray(a, dtype=None)[源代码]
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 isNone
, the data type of the new tensor will be inferred from obj. Default isNone
.
- 返回
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]