speed of numpy.power()?

Hrvoje Niksic hniksic at xemacs.org
Wed Aug 25 10:41:27 EDT 2010


Carlos Grohmann <carlos.grohmann at gmail.com> writes:

> I'd like to hear from you on the benefits of using numpy.power(x,y)
> over (x*x*x*x..)
>
> I looks to me that numpy.power takes more time to run.

You can use math.pow, which is no slower than repeated multiplication,
even for small exponents.

Obviously, after the exponent has grown large enough, numpy.power
becomes faster than repeated exponentiation (it's already faster at
100).  Like math.pow, it supports negative and non-integer exponents.
Unlike math.pow, numpy.power also supports all kinds of interesting
objects as bases for exponentiation.



More information about the Python-list mailing list