4

numpy_array

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.

0

1 Answer 1

2

If you check the documentation of np.max, you'll see it takes an axis argument:

a.max(axis=0)

But that won't help you yet. However, there's a function argmax that gives you the indices of the maxima along a given axis:

a.argmax(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) with a[...,0].max(axis=1) (or 0), and use that to find the values on the other sides.

Sign up to request clarification or add additional context in comments.

2 Comments

And how can I get the "layer numbers" of the max values?
Thanks!Actually the argmax(axis=0) returns the array I need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.