给定一个 CuPy 数组a
,有两种方法可以从中获取 numpy 数组:a.get()
和cupy.asnumpy(a)
。它们之间有什么实际区别吗?
import cupy as cp
a = cp.random.randint(10, size=(4,5,6,7))
b = a.get()
c = cp.asnumpy(a)
assert type(b) == type(c) and (b == c).all()
Run Code Online (Sandbox Code Playgroud)