PatriceG
PatriceG

Reputation: 4063

Numpy argmax. How to compute both max and argmax?

Is there a way to get max and argmax by one stroke ?

import numpy as np
a=[0,0,1,0]
maximum=max(a)
index=np.argmax(a)

Is there a fastest way to do it, with something like:

[maximum,index]=function(a)

Upvotes: 43

Views: 28346

Answers (1)

PatriceG
PatriceG

Reputation: 4063

Maybe something like this is faster...

index = np.argmax(a)
maximum = a[index]

Upvotes: 43

Related Questions