I have a two-dimensional array and index it with a pair of arrays (in fact my arrays are much larger, millions of elements):
a = np.array([[1, 2, 3], [4, 5, 6]])b = a[[0, 0, 0, 1], [0, 1, 2, 0]]Indexing will allocate a new array. Is there a way to do this indexing with an output array provided?
I looked at np.take and np.choose, but it seems that they don't work with a pair of arrays. I managed to use np.take(..., out=buf) if I ravel the array and manually construct the 1-d instance, but it causes more memory accesses, and almost kills the improvement over eliminating allocation for the indexing result.