Index of maximum value of each row of an array in Python

I have an array Pr. I want to print index of maximum value of each row. For example, for row 0, the maximum value is 1.72731864e+003 and it occurs at index 0. I present the expected output.

import numpy as np 
Pr = np.array([[1.72731864e+003, 0.00000000e+000],
       [0.00000000e+000, 1.24439020e+003]])


The expected output is


>Solution :

try using np.argmax function. it is used to find the index of the maximum value along the specified axis, which in this case is axis 1 (i.e., the rows). The resulting array of indices is then printed to the console. so indices = np.argmax(Pr, axis=1) print(indices)

Leave a Reply