Reputation: 51
We need a maximum value from a numpy array with 3 columns.
Sample, i need the maximum value per array of the last column. In this case the result is: 57.65048981 for the first array, 58.3501091 for the second and 56.86465836 for the third. How to get these 3 values in an array included by the 2 2 values in the columns before?
[array([[ 402. , 242. , 57.65048981],
[ 401. , 243. , 56.32482529]]),
array([[ 356. , 257. , 53.3116188 ],
[ 355. , 258. , 53.69690704],
[ 356. , 258. , 57.52435684],
[ 355. , 259. , 56.98838806],
[ 356. , 259. , 57.81959152],
[ 354. , 260. , 55.90369415],
[ 355. , 260. , 58.14822769],
[ 356. , 260. , 58.3501091 ],
[ 354. , 261. , 55.1479187 ],
[ 355. , 261. , 58.20180893],
[ 354. , 262. , 54.5345459 ]]),
array([[ 386. , 260. , 56.86465836],
[ 386. , 261. , 54.28659439],
[ 386. , 259. , 56.53445435]])]
The result of this should be:
[[402, 242, 57.65048981],
[356 ,260, 58.3501091],
[386 ,260, 56.86465836]]
Upvotes: 0
Views: 1965
Reputation: 13485
I think there's an error in your "results"
np.array([arr[np.argmax(arr[:, 2]), :] for arr in arrays])
returns
array([[ 402. , 242. , 57.65048981],
[ 356. , 260. , 58.3501091 ],
[ 386. , 260. , 56.86465836]])
Upvotes: 4