【问题标题】:find the max from each row in python从python中的每一行中找到最大值
【发布时间】:2018-08-08 06:49:54
【问题描述】:
0.511474    0.488526
0.468783    0.531217
0.35111     0.64889
0.594834    0.405166

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

0.511474
0.531217
0.64889
0.594834

【问题讨论】:

  • 是行列表,df 等?
  • df.max(axis=1).values

标签: python numpy dataframe


【解决方案1】:

使用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]])
# axis=1 to find max from each row
x = np.amax(a, axis=1)
print(x)

返回:

[0.511474 0.531217 0.64889  0.594834]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    相关资源
    最近更新 更多