Skip to content
Advertisement

Difference between cupy.asnumpy() and get()

Given a CuPy array a, there are two ways to get a numpy array from it: a.get() and cupy.asnumpy(a). Is there any practical difference between them?

JavaScript

Advertisement

Answer

cp.asnumpy is a wrapper calling ndarray.get. You can see that in the code of cp.asnumpy:

JavaScript

As you can see (both in the documentation and in the code), cp.asnumpy supports more input types than just CuPy arrays. It supports inputs that are CUDA objects with the __cuda_array_interface__ attribute and any objects that can be actually converted to a Numpy array. This includes Numpy arrays themselves and iterables (eg. list, generators, etc.).

Advertisement