mindspore.numpy.asfarray
- mindspore.numpy.asfarray(a, dtype=mstype.float32)[源代码]
Similar to asarray, converts the input to a float tensor.
If non-float dtype is defined, this function will return a float32 tensor instead.
- 参数
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 a. Default ismindspore.float32
.
- 返回
Tensor, generated tensor with the specified float 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.asfarray([1,2,3])) [1. 2. 3.]