from_numpy
- paddle. from_numpy ( ndarray: NDArray[Any] ) paddle.Tensor [source]
-
Creates a
paddle.Tensorfrom anumpy.ndarray.The returned Tensor and the input
ndarrayshare the same underlying memory. Changes to the Tensor will be reflected in thendarrayand vice versa.- Parameters
-
ndarray (numpy.ndarray) – The numpy ndarray to be converted to a Tensor.
- Returns
-
A Tensor that shares the same memory with the input
ndarray. - Return type
-
Tensor
Examples
>>> import paddle >>> import numpy as np >>> np_data = np.array([1, 2, 3]).astype('int64') >>> tensor = paddle.from_numpy(np_data) >>> print(tensor) Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True, [1, 2, 3])
