How to find the max from each row in Python and store it in a NumPy array or Pandas DataFrame and store it in a NumPy array, i.e. the output below?
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
function. 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)
which returns:
[0.511474 0.531217 0.64889 0.594834]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With