如何使用cython访问运行时确定形状的numpy数组中的特定位置?
shape = (2,3,4)
x = np.zeros(shape=shape)
x[(0, 1, 2)] # standard
x[[0], [1], [2]] # standard
cdef np.ndarray loc = np.zeros(len(shape), dtype=np.int)
x[loc] # doesn't work since x[[1,2,3]]
x[tuple(loc)] # works but I assume is not as fast as can be made
作为推论,形状在程序的整个操作中保持一致,通过设置+读取文件确定。是否可以/更好地将计算形状移动到程序执行之前并使用此计算来利用ndim在接受数组x的函数中?我对静态类型没什么经验。