mindspore.Tensor.from_numpy

View Source On Gitee
static Tensor.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
>>> from mindspore import Tensor
>>> x = np.array([1, 2])
>>> output = Tensor.from_numpy(x)
>>> print(output)
[1 2]