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]
Share:
12,126

Related videos on Youtube

Dinesh Beura
Author by

Dinesh Beura

Updated on June 04, 2022

Comments

  • Dinesh Beura
    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
      Alexander over 5 years
      df.max(axis=1).values