如何在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/