I'm trying to understand what the following does at a conceptual level. Let's say we have two numpy arrays of random integers
arr1
array([[2, 2, 2, 2, 1],
[1, 3, 1, 3, 2],
[2, 2, 2, 1, 3],
[1, 1, 1, 3, 2]])
arr2
array([[1, 3, 1, 1, 3, 3, 2, 2],
[2, 3, 2, 2, 2, 3, 2, 1],
[3, 3, 3, 1, 1, 3, 3, 3],
[1, 1, 2, 1, 2, 1, 1, 1]])
Then, I do a nested indexing of the second array arr2 into the first one arr1, obtaining
arr1[arr2,:]
array([[[1, 3, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 3, 1, 3, 2],
[1, 3, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 1, 1, 3, 2],
[2, 2, 2, 1, 3],
[2, 2, 2, 1, 3]],
[[2, 2, 2, 1, 3],
[1, 1, 1, 3, 2],
[2, 2, 2, 1, 3],
[2, 2, 2, 1, 3],
[2, 2, 2, 1, 3],
[1, 1, 1, 3, 2],
[2, 2, 2, 1, 3],
[1, 3, 1, 3, 2]],
[[1, 1, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 3, 1, 3, 2],
[1, 3, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 1, 1, 3, 2],
[1, 1, 1, 3, 2]],
[[1, 3, 1, 3, 2],
[1, 3, 1, 3, 2],
[2, 2, 2, 1, 3],
[1, 3, 1, 3, 2],
[2, 2, 2, 1, 3],
[1, 3, 1, 3, 2],
[1, 3, 1, 3, 2],
[1, 3, 1, 3, 2]]])
which is a new array with shape (4,8,5). It is not clear to me how should I interpret this new object, and how the entries of the two arrays are actually combined together.
arr2with the corresponding row of `arr1'. Hence the (4,8) shape has expanded to (4,8,5).