What is the most elegant way to access an n dimensional array with an (n-1) dimensional array along a given dimension as in the dummy example
a = np.random.random_sample((3,4,4))
b = np.random.random_sample((3,4,4))
idx = np.argmax(a, axis=0)
How can I access now with idx a
to get the maxima in a
as if I had used a.max(axis=0)
? or how to retrieve the values specified by idx
in b
?
I thought about using np.meshgrid
but I think it is an overkill. Note that the dimension axis
can be any usefull axis (0,1,2) and is not known in advance. Is there an elegant way to do this?