简体   繁体   中英

numpy find maximum digit in array

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]]]

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, :]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM