0

I have a numpy array of shape (1, 7, 3) i would like to find the row with highest element in the 3 column. Eg.: 232 is the biggest in the 3rd column so it should output [196 228 232] How can I do it? I tried np.argmax but failed

Here is an example array:

[[[218 204 204]
[344 194  31]
[284 140 108]
[196 228 232]
[324 196  28]
[224 228  57]
[174 250 144]]]
4
  • maybe this link might help stackoverflow.com/questions/12403238/… Commented Feb 20, 2017 at 23:40
  • Possible duplicate of Maximum values along axis of Numpy ndarray? Commented Feb 20, 2017 at 23:41
  • a.max(axis=2) returns [218 344 284 232 324 228 250] which is max value of each row and i need element with largest row[2] element as in question Commented Feb 20, 2017 at 23:45
  • Highest digit (e.g. 9) or value? Commented Feb 20, 2017 at 23:46

1 Answer 1

1

argmax is the right idea here. let's do it step by step.

 row_nr = np.argmax(data[0, :, 2])

this selects the third column and finds the index of the largest value. it remains to select this row:

data[0, row_nr, :]
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for taking time to read and answer my question. It makes perfect sense now

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.