[Numpy-discussion] avoiding the matrix copy performance hit

Travis Oliphant oliphant.travis at ieee.org
Mon Feb 13 20:35:13 EST 2006


Tim Hochberg wrote:

> Bill Baxter wrote:
>
>> Is there anyway to get around this timing difference?
>> *
>>   >>> import timeit
>> **  >>> t1 = timeit.Timer("a = zeros((1000,1000),'d'); a += 1.;",  
>> 'from numpy import zeros,mat')
>> **  >>> t2 = timeit.Timer("a = mat(zeros((1000,1000),'d')); a += 
>> 1.;",  'from numpy import zeros,mat')
>>   >>> **t1.timeit(100)
>>   1.8391627591141742
>>   >>> t2.timeit(100)
>>   3.2988266117713465
>>
>> *Copying all the data of the input array seems wasteful when the 
>> array is just going to go out of scope.  Or is this not something to 
>> be concerned about? 
>

I think I originally tried to make mat *not* return a copy, but this 
actually broke code in SciPy.  So, I left the default as it was as a 
copy on input.  There is an *asmatrix* command that does not return a 
copy...

-Travis





More information about the NumPy-Discussion mailing list