speed of numpy.power()?
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
On 25/08/2010 14:59, Carlos Grohmann wrote: 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
Carlos Grohmann carlos.grohm...@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. -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
On Wed, Aug 25, 2010 at 10:59 PM, Carlos Grohmann carlos.grohm...@gmail.com wrote: 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
On 25 ago, 12:40, David Cournapeau courn...@gmail.com wrote: 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
On 8/25/10 8:59 AM, Carlos Grohmann wrote: 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
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. -- To email me, substitute nowhere-spamcop, invalid-net. -- http://mail.python.org/mailman/listinfo/python-list
Re: speed of numpy.power()?
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 -- http://mail.python.org/mailman/listinfo/python-list