[Numpy-discussion] Vectorizing code, for loops, and all that

Travis Oliphant oliphant.travis at ieee.org
Tue Oct 3 10:59:18 EDT 2006


Albert Strasheim wrote:
>>> [1] 12.97% of function time
>>> [2] 8.65% of functiont ime
>>> [3] 62.14% of function time
>>>
>>> If statistics from elsewhere in the code would be helpful, let me 
>>> know,
>>>       
>> and
>>     
>>> I'll see if I can convince Quantify to cough it up.
>>>
>>>       
>> Please run the same test but using
>>
>> x1 = N.random.rand(39,2000)
>> x2 = N.random.rand(39,64,1)
>>
>> z1 = x1[:,N.newaxis,:] - x2
>>     
>
> Very similar results to what I had previously:
>
> [1] 10.88%
> [2] 7.25%
> [3] 68.25%
>
>   
Thanks,

I've got some ideas about how to speed this up by eliminating some of 
the unnecessary calculations  going on outside of the function loop, but 
there will still be some speed issues depending on how the array is 
traversed once you get above a certain size.   I'm not sure there anyway 
around that, ultimately, due to memory access being slow on most hardware. 

If anyone has any ideas, I'd love to hear them.    I won't be able to 
get to implementing my ideas until at least Friday (also when rc2 will 
be released).


-Travis





More information about the NumPy-Discussion mailing list