I want a easy to read access to some parts of a multidimensional numpy array. For any array accessing the first dimension is easy (b[index]). Accessing the sixth dimension on the other hand is "hard" (especially to read).
b[:,:,:,:,:,index] #the next person to read the code will have to count the :
Is there a better way to do this? Especially is there a way, where the axis is not known while writing the program?
Edit: The indexed dimension is not necessarily the last dimension
You can use np.take.
For example:
b.take(index, axis=5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With