speed of numpy.power()?

C

Carlos Grohmann

Hi all,

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.

cheers

Carlos
 
M

Mark Lawrence

Hi all,

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.

cheers

Carlos

Measure it yourself using the timeit module.

Cheers.

Mark Lawrence.
 
H

Hrvoje Niksic

Carlos Grohmann said:
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.
 
D

David Cournapeau

Hi all,

I'd like to hear from you on the benefits of using numpy.power(x,y)
over (x*x*x*x..)

Without more context, I would say None if x*x*x*x*... works and you
are not already using numpy. The point of numpy is mostly to work on
numpy arrays, and to support types of data not "natively" supported by
python (single, extended precision). If x is a python object such as
int or float, numpy will also be much slower. Using numpy would make
sense if for example you are already using numpy everywhere else, for
consistency reason,

David
 
C

Carlos Grohmann

On Wed, Aug 25, 2010 at 10:59 PM, Carlos Grohmann
Thanks David and Hrvoje. That was the feedback I was looking for.

I am using numpy in my app but in some cases I will use math.pow(),
as some tests with timeit showed that numpy.power was slower for
(x*x*x*x*x).

best

Carlos
 
R

Robert Kern

Hi all,

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 will want to ask numpy questions on the numpy mailing list:

http://www.scipy.org/Mailing_Lists

The advantage that numpy.power(x,y) has over (x*x*x...) is that y can be
floating point. We do not attempt to do strength reduction in the integer case.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
P

Peter Pearson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top