[SciPy-user] Speed differences in sqrt calculation: what is good to know

David Cournapeau david@ar.media.kyoto-u.ac...
Wed Jun 11 10:54:43 CDT 2008

Ivo Maljevic wrote:
> Based on comments from Gael Varoquaux and David Cournapeau , I did the 
> execution time test.
> At least for me, it is clear that if the number is a real scalar, AND 
> the expected result is also real,
> the best way is to call the math version of sqrt() function. The 
> differences are more than significant, as you can see:

It is expected for numpy/scipy functions to be much slower than python 
*for scalar*. Since they are optimized to be used with arrays, you are 
paying the cost to initialize the machinery to handle arrays (ufunc), 
without the benefit.

The problem really is the difference between numpy and scipy. The funny 
thing is that for arrays, scipy.sqrt (that is, numpy.lib.scimath.sqrt) 
is faster than numpy.sqrt, which does not quite make sense to me since 
scipy.sqrt calls numpy.sqrt... But it is 1 a.m, so maybe I should just 
get some sleep



More information about the SciPy-user mailing list