Reputation: 335
I have an array that looks like this:
ar=[[[678,701]],
[[680,702]],
[[674,710]],
...]
I have to find extrema for each of the column (i.e., for these 678,680,674... and for 701,702,710,... independently).
I tried to access these columns with something like this:
ar[:][0][0]
or ar[:][0][1]
but it turned out, that the Python understood ar[:][0]
just the same as ar[0]
, and because of that I don't know any way to prevent from using loops. Are there still any sophisticated technique to do that?
Upvotes: 0
Views: 185
Reputation: 69172
To find the extrema along particular axes, you can use the axis
parameter:
import numpy as np
ar = np.array([[[678,701]],
[[680,702]],
[[674,710]],
])
print ar.max(axis=0) # [[680 710]]
print ar.max(axis=0) # [[674 701]]
To slice out the two columns, you can use:
print ar[:,0,0] # [678 680 674]
print ar[:,0,1] # [701 702 710]
Upvotes: 1