mindspore.numpy.array
- mindspore.numpy.array(obj, dtype=None, copy=True, ndmin=0)[源代码]
Creates a tensor.
This function creates tensors from an array-like object.
- 参数
obj (Union[int, float, bool, list, tuple]) – 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
.copy (bool) – If True, then the object is copied. Otherwise, a copy will only be made if necessary. Default: True.
ndmin (int) – Specifies the minimum number of dimensions that the resulting tensor should have. Ones will be pre-pended to the shape as needed to meet this requirement. Default: 0
- 返回
Tensor, generated tensor with the specified dtype.
- 异常
TypeError – If input arguments have types not specified above.
ValueError – If input obj has different sizes at different dimensions.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> print(np.array([1,2,3])) [1 2 3]