简体   繁体   中英

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, ie 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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM