Issue
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
Solution
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]
Answered By - U3.1415926
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.