find the max from each row in python
12,126
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]
Related videos on Youtube
Author by
Dinesh Beura
Updated on June 04, 2022Comments
-
Dinesh Beura almost 2 years
0.511474 0.488526 0.468783 0.531217 0.35111 0.64889 0.594834 0.405166
"how to find the max from each row in python and store it in an numpy array or pandas Dataframe and store it in an numpy array , i.e the output below"
0.511474 0.531217 0.64889 0.594834
-
Alexander over 5 years
df.max(axis=1).values
-