如何在Python中找到每一行的最大值并将其存储在NumPy数组或Pandas DataFrame中并将其存储在NumPy数组中,即下面的输出?
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
功能。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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)