numpy.from_dlpack#

numpy.from_dlpack(x,/,*,device=None,copy=None)#

Create a NumPy array from an object implementing the__dlpack__protocol. Generally, the returned NumPy array is a view of the inputobject. See[1] and[2] for more details.

Parameters:
xobject

A Python object that implements the__dlpack__ and__dlpack_device__ methods.

devicedevice, optional

Device on which to place the created array. Default:None.Must be"cpu" if passed which may allow importing an arraythat is not already CPU available.

copybool, optional

Boolean indicating whether or not to copy the input. IfTrue,the copy will be made. IfFalse, the function will never copy,and will raiseBufferError in case a copy is deemed necessary.Passing it requests a copy from the exporter who may or may notimplement the capability.IfNone, the function will reuse the existing memory buffer ifpossible and copy otherwise. Default:None.

Returns:
outndarray

References

Examples

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