Home > Back-end >  find the maximum value of a row index in a numpy array?
find the maximum value of a row index in a numpy array?

Time:12-07

I have the following array:

a = [[0.         0.        ]
     [0.22333333 0.14333333]
     [0.48166667 0.99      ]
     [0.735      1.66666667]
     [1.02666667 2.16666667]
     [1.43833333 2.66333333]
     [1.71666667 3.15666667]]

I want to be able to find the maximum value at a specific row index. For instance, the maximum value for row 2 is 0.99, row 6 would be 3.15.

I know i can use

np.max(array,axis=1)

which produces this:

[0.         0.22333333 0.99       1.66666667 2.16666667 2.66333333
  3.15666667]

but I only want one value for the row I'm interested in. For instance, if i only want the max value of row 2 in the array, then the output value should look like this only:

0.99

CodePudding user response:

or something like that

np.amax(a[row])

CodePudding user response:

Well then just apply max on that row you want? e.g. array[2].max()

  • Related