[Numpy-discussion] Square All Elements Of A Matrix

David M. Cooke cookedm at physics.mcmaster.ca
Wed May 11 13:58:20 EDT 2005


andrea_gavana at tin.it writes:

> Hello David
>>Hmm, I don't see this, with either 23.8 or 24.0b2. What version of
>>Numeric are you using, and on what platform?
>
> I have currently Numeric 23.8, with numarray 1.3.1. I am on a Windows XP
> machine, with 1 GB RAM and 3.0 GHz. My Python version is 2.3.4.
>
>>dx**2 uses the C 'pow' function on each element (so using 2 or 2.0
>>here doesn't make a difference), so may be your platform pow() is
>>slow.
>
> Probably that is the reason... but why? Is Windows the problem?
>
>>dx*dx should be faster (it takes 80% of the time that dx**2 does on my
>>machine).
>
> On my machine, dx*dx is istantaneous (about 0.1 secons). This are my timings:
>
> import time; start = time.time(); td = dx*dx; print time.time() - start
> 0.121000051498
>
> import time; start = time.time(); td = dx**2; print time.time() - start
> 4.367000103
>
> !!!!!!!!

Could you check the speed of

td = exp(2*log(dx))

If it's comparable to dx**2, then your pow() library function isn't
any good :-( -- it's not special-casing integer powers.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the NumPy-Discussion mailing list