I’m afraid that I can’t describe the problem so I draw a sketch of it.Anyway,what I need is to find the max values along the 0th axis in a numpy ndarray,i.e.array.shape(5,5,3), and their corresponding "layer numbers", and use the "layer numbers" to create a new 2d array with shape of (1,5,3).Hope I’m giving a clear description here..thanks a lot.
Share

If you check the documentation of
np.max, you’ll see it takes anaxisargument:But that won’t help you yet. However, there’s a function
argmaxthat gives you the indices of the maxima along a given axis:So, let’s find your first (5,5) array: it’s
a[...,0]. You can find the position of the maxima per rows (or columns) witha[...,0].max(axis=1)(or 0), and use that to find the values on the other sides.