从python中的每一行中找到最大值

Din*_*ura 4 python numpy dataframe

0.511474    0.488526
0.468783    0.531217
0.35111     0.64889
0.594834    0.405166
Run Code Online (Sandbox Code Playgroud)

“如何从python中的每一行中找到最大值并将其存储在一个numpy数组或pandas Dataframe中并将其存储在一个numpy数组中,即下面的输出”

0.511474
0.531217
0.64889
0.594834
Run Code Online (Sandbox Code Playgroud)

U3.*_*926 7

使用该numpy amax功能。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]])
x = np.amax(a, 1)
print(x)
Run Code Online (Sandbox Code Playgroud)

返回:

[0.511474 0.531217 0.64889  0.594834]
Run Code Online (Sandbox Code Playgroud)