Olivier vd Sloot
Olivier vd Sloot

Reputation: 51

max value from specified column in numpy array

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

Answers (1)

Peter
Peter

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

Related Questions