mindspore.from_numpy

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

Convert numpy array to Tensor. If the data is not C contiguous, the data will be copied to C contiguous to construct the tensor. Otherwise, the tensor will be constructed using this numpy array without copy.

Parameters

array (numpy.array) – The input array.

Returns

Tensor, has the same data type as 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]