Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find the max from each row in python

How to find the max from each row in Python and store it in a NumPy array or Pandas DataFrame and store it in a NumPy array, i.e. the output below?

0.511474    0.488526
0.468783    0.531217
0.35111     0.64889
0.594834    0.405166

Output:

0.511474
0.531217
0.64889
0.594834
like image 251
Dinesh Beura Avatar asked Mar 06 '23 16:03

Dinesh Beura


1 Answers

Use the numpy amax function. np.amax

import numpy as np
a = np.array([[0.511474,    0.488526],
            [0.468783,    0.531217],
            [0.35111,     0.64889],
            [0.594834,    0.405166]])
# axis=1 to find max from each row
x = np.amax(a, axis=1)
print(x)

which returns:

[0.511474 0.531217 0.64889  0.594834]
like image 84
U3.1415926 Avatar answered Mar 29 '23 20:03

U3.1415926