0

I have an array:

x = array([[[ 0,  1,  2],
        [ 6,  7,  8],
        [12, 13, 14]],

       [[ 3,  4,  5],
        [ 9, 10, 11],
        [15, 16, 17]],

       [[18, 19, 20],
        [24, 25, 26],
        [30, 31, 32]],

       [[21, 22, 23],
        [27, 28, 29],
        [33, 34, 35]]])

I want to find the max values of each subarrays and store them in lets say an array. So the output should be:

output = array([14,17,32,35])

Now, one can easily do this using a loop, however, I want to avoid it. np.max(x) is giving output 35, that is the max value of the entire array. np.max(axis) also is not working (I am not very sure it would work, but I tried anyway) Anyone, can you help?

2 Answers 2

2

Simply:

[max(j) for j in [max(i) for i in x.tolist()]]

Output:

[14, 17, 32, 35]

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

2 Comments

but my required output, as I mentioned in the question is: [14,17,32,35]
I edited my response to reflect the change.
1

You can use np.max for axis=1 twice

x.max(axis=1).max(axis=1)   

OUTPUT

Out[203]: array([14, 17, 32, 35])

Comments

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.