确保您可以使用高级索引来做到这一点,这是否是最快的方法可能取决于您的数组大小(如果行很大,则可能不是):
rows, column_indices = np.ogrid[:A.shape[0], :A.shape[1]]# Use always a negative shift, so that column_indices are valid.# (could also use module operation)r[r < 0] += A.shape[1]column_indices = column_indices - r[:, np.newaxis]result = A[rows, column_indices]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)