0

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]]
4
  • Is that list of numpy arrays? Commented May 2, 2015 at 7:56
  • The sample output doesn't match your description. Which one is wrong? Commented May 2, 2015 at 7:56
  • Now its corrected thanks! Commented May 2, 2015 at 7:59
  • I assume the bottom right value should be 56.86465836? Commented May 2, 2015 at 8:00

1 Answer 1

4

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]])
Sign up to request clarification or add additional context in comments.

1 Comment

Quick that was - was about to post [arr[arr[:, -1].argmax(), :].tolist() for arr in arrays] - this will give list of lists as the OP wanted.

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.