[Numpy-discussion] spurious IndexError?

john saponara john at saponara.net
Tue Aug 7 22:50:05 EDT 2007

Using numpy-1.0.2/python-2.5/winxp pro sp2:  in the following, the only 
array is 'a', and I'm not using it as an index, so why do I get the 
IndexError below?

--- start python session ---
 >>> a=array([[1,3],[2,4]])
 >>> a
array([[1, 3],
        [2, 4]])
 >>> f=lambda i,j: a[i,j]
 >>> f(1,1)
 >>> fromfunction(f,(2,2))
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "C:\Python25\Lib\site-packages\numpy\core\numeric.py", line 514, 
in fromfunction
	return function(*args,**kwargs)
   File "<stdin>", line 1, in <lambda>
IndexError: arrays used as indices must be of integer (or boolean) type
--- end python session ---

The upstream maple is written in 'fromfunction' style, and I have no 
control over that but want to port it to python in the most natural way 

The session suggests that lambda has no trouble with an array, so the 
problem seems to be related to the way 'fromfunction' works.  What am I 


More information about the NumPy-Discussion mailing list