numpy.from_dlpack#

numpy.from_dlpack(x, /)#

Create a NumPy array from an object implementing the __dlpack__ protocol. Generally, the returned NumPy array is a read-only view of the input object. See [1] and [2] for more details.

Parameters:
xobject

A Python object that implements the __dlpack__ and __dlpack_device__ methods.

Returns:
outndarray

References

Examples

>>> import torch  
>>> x = torch.arange(10)  
>>> # create a view of the torch tensor "x" in NumPy
>>> y = np.from_dlpack(x)