这些作业有效:
cdef double[:,::1] test2d = np.array([[0,1],[2,3],[4,5]], dtype=np.double)
cdef double[:,::1] temp = np.array([[4,5],[6,7]], dtype=np.double)
test2d[...] = 4
test2d[:,1] = np.array([5],dtype=np.double)
test2d[1:,:] = temp
print np.asarray(test2d)
显示
[[ 4. 5.]
[ 4. 5.]
[ 6. 7.]]
我已在以下位置添加了答案https://stackoverflow.com/a/30418422/901925 https://stackoverflow.com/a/30418422/901925在缩进上下文中使用这种内存视图“缓冲区”方法。
cpdef int testfunc1c(np.ndarray[np.float_t, ndim=2] A,
double [:,:] BView) except -1:
cdef double[:,:] CView
if np.isnan(A).any():
return -1
else:
CView = la.inv(A)
BView[...] = CView
return 1
它不执行其他发布者想要的无复制缓冲区分配,但它仍然是有效的内存视图复制。