Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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]])

MaxPr=Pr.max(axis=1)

The expected output is

indices=[0,1]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading