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.
- Parameters
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
.
- Returns
Tensor, generated tensor with the specified float dtype.
- Raises
TypeError – If input arguments have types not specified above.
ValueError – If input a has different sizes at different dimensions.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> print(np.asfarray([1,2,3])) [1. 2. 3.]