[Numpy-discussion] when and where to use numpy arrays vs nested lists

Mark P. Miller mpmusu at cc.usu.edu
Thu Mar 1 13:27:44 EST 2007


Travis:  Can you clarify this for me.  The book doesn't have much detail 
here and seems to differ from your notation (which gives me errors).

>> Getting single indices like this is a bit slower for NumPy then for 
>> lists because of all the possibilities that must be distinguished for 
>> array indexing.   List indexing is a very simple thing.  Thus, lists can 
>> be seen as collections that are optimized for simple indexing.  If all 
>> you are doing is simple indexing, then lists are going to be faster.
>>
>> You can try using array1.item(randint(10), randint(10)), like this:
>>
>> getitem = array1.item
>> def random1():
>>       getitem(randint(50), randint(50))
>>
> 
> 
 >>> array1=numpy.zeros((10,10),int)
 >>> array1.item(0,0)
Traceback (most recent call last):
   File "<pyshell#43>", line 1, in ?
     array1.item(0,0)
TypeError: function takes exactly 0 arguments (2 given)

 >>> getitem = array1.item
 >>> getitem(0,0)
Traceback (most recent call last):
   File "<pyshell#55>", line 1, in ?
     getitem(0,0)
TypeError: function takes exactly 0 arguments (2 given)


I also assume that .itemset should do the converse?  However, the syntax 
escapes me.

python 2.4.3
numpy 0.9.9.2706
WinXP

Thanks,

-Mark

> 
> 
>> _______________________________________________
>> Numpy-discussion mailing list
>> Numpy-discussion at scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list