mindspore.from_numpy

View Source On AtomGit
mindspore.from_numpy(array)[source]

Convert a NumPy array to Tensor. If the data is not C contiguous, the data will be copied to be C contiguous, and then the tensor is constructed. Otherwise, the tensor will be constructed using this NumPy array without copy.

Parameters

array (numpy.ndarray) – The input array.

Returns

Tensor, which has the same data type as the input array.

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> x = np.array([1, 2])
>>> output = ms.from_numpy(x)
>>> print(output)
[1 2]