mindspore.Tensor.from_numpy

View Source On AtomGit
static Tensor.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.

Warning

This interface is deprecated and will be removed after version 2.9.0.

Parameters:

array (numpy.ndarray) – The input array.

Returns:

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