speed of numpy.power()?

Dave Angel davea at ieee.org
Wed Aug 25 17:05:27 EDT 2010


Peter Pearson wrote:
> On Wed, 25 Aug 2010 06:59:36 -0700 (PDT), Carlos Grohmann wrote:
> 	>
>   
>> I'd like to hear from you on the benefits of using numpy.power(x,y)
>> over (x*x*x*x..)
>>
>>     
>
> Using the "dis" package under Python 2.5, I see that
> computing x_to_the_16 = x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x uses
> 15 multiplies.  I hope that numpy.power does it with 4.
>
>   
Right. Square/multiply algorithm takes something like 2*(log2(y)) 
multiplies worst case.

That should not only be faster, but quite likely more accurate, at least 
for non-integer x values and large enough integer y.

DaveA



More information about the Python-list mailing list