Home > Net >  Return a 1D numpy array of a specific index from an axis in 2D array
Return a 1D numpy array of a specific index from an axis in 2D array

Time:11-16

This should be trivial but I'm not finding the correct way to accomplish it. I have a 2D array with shape (5, 5527) I have an an array of indices with the lowest value for the arguments in the first axis with shape (5527,)

How can I flatten my (5,5527) array into a 1D array by only using the values at the index specified by the index array?

I thought np.take would accomplish this but it does not. It outputs an array with shape (5527,5527)

CodePudding user response:

You were close: np.take_along_axis

  • Related