[Numpy-discussion] argmax()

Niklas Saers niklassaers at gmail.com
Mon Jan 1 06:15:08 CST 2007


Hi,
I'm quite new to numpy. My understanding of argmax() is that it gives  
the index of the highest number in the array, just like:

from numpy import *
a=array(range(4096))
a=a*15
argmax(a)

gives 4095.

But, when I use this within my program I have a little function:

def localMaxima(set):
	maxPos  = argmax(set)
	maxVal = set[maxPos]
	return maxPos, maxVal

that I have had to extend a little bit to:

def localMaxima(set):
	maxPos  = argmax(set)
	try:
	  maxVal = set[maxPos]
	  print "ok"
	except:
	  print "maxPos = " + str(maxPos) + ", while len(set) is " + str(len 
(set))
	  print set
	  maxVal = 0.0
	return maxPos, maxVal

The problem is that set is an array of 2048 numbers. However, when I  
run this function I get:
"maxPos = 7925760, while len(set) is 2048"

I do not understand why I get such a high index. Do you have any  
suggestions?

Cheers

     Nik


More information about the Numpy-discussion mailing list