python - 在 Python 中查找每一行的最大值

标签 python numpy dataframe

如何在Python中找到每一行的最大值并将其存储在NumPy数组或Pandas DataFrame中并将其存储在NumPy数组中,即下面的输出?

0.511474    0.488526
0.468783    0.531217
0.35111     0.64889
0.594834    0.405166

输出:

0.511474
0.531217
0.64889
0.594834

最佳答案

使用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]

关于python - 在 Python 中查找每一行的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51740214/

相关文章:

python - Pandas:在具有不同名称的字段上加入 DataFrames?

python - 导入错误 : Google Analytics API Authorization

python - Opencv写视频正在运行,但保存的output.avi文件为0KB

python - 如何通过广播将numpy数组与 Pandas 数据帧相乘

python - 将 hdf5 文件组合成单个数据集

python - Pandas 有条件创建系列/数据框列

r - 从日期列创建假期的指示变量

python - 正则表达式返回两个特殊字符之间的所有字符

python - 将内存中的 OpenCV 图像写入 BytesIO 或 Tempfile

python - 无法绘制石榴图(找不到 pygraphviz)