Numpy argmax

import numpy as np

x = np.array([[2,3,4,5],[12,23,44,25],[12,33,64,85]])

print(x)

print()

print(‘Index of largest element: ‘,np.argmax(x))


print(‘Indices of largest element along axis=0 (Column-wise): ‘,np.argmax(x,axis=0))
print(‘Indices of largest element along axis=1: (Row-wise)’,np.argmax(x,axis=1))


Output

[[ 2 3 4 5]
[12 23 44 25]
[12 33 64 85]]

Index of largest element: 11
Indices of largest element along axis=0 (Column-wise): [1 2 2 2]
Indices of largest element along axis=1: (Row-wise) [3 2 3]

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.