Skip to content
Advertisement

Slice multidimensional numpy array from max in a given axis

I have a 3-dimensional array a of shape (n, m, l). I extract one column j from it’s last axis and compute the maximum index along the first axis like follows:

JavaScript

Now I’d like to slice the original array a to get all the information based on the index where the column j is maximal. I.e. I’d like an numpythonic way to do the following using array broadcasting or numpy functions:

JavaScript

Is there one?

Advertisement

Answer

As @hpaulj mentionned in the comments, using a[wheremax, np.arange(m)] did the trick.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement