[Tutor] power of 2.718282

Marc Tompkins marc.tompkins at gmail.com
Tue Jan 13 19:25:16 CET 2009


On Tue, Jan 13, 2009 at 10:19 AM, culpritNr1 <ig2ar-saf1 at yahoo.co.uk> wrote:
>
> How do I compute a power of e in Python?
>
> Say I need 2.718282 to the 10th. In R for example, I just do exp(10).
>
> I would appreciate a low level solution because I have to iteratively call
> that computation millions of times. Anything more efficient than
> 2.718182**10 may be good.
>

Import the "math" module.  From the 2.6 docs:

Power and logarithmic functions
>
> math.exp(x)
>  Return e**x.
>
> math.log(x[, base])
>  Return the logarithm of x to the given base. If the base is not specified,
> return the natural logarithm of x (that is, the logarithm to base e).
>  Changed in version 2.3: base argument added.
>
> math.log1p(x)
>  Return the natural logarithm of 1+x (base e). The result is calculated in
> a way which is accurate for x near zero.
>  New in version 2.6.
>
> math.log10(x)
>  Return the base-10 logarithm of x.
>
> math.pow(x, y)
>  Return x raised to the power y. Exceptional cases follow Annex 'F' of the
> C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0)
> always return 1.0, even when x is a zero or a NaN. If both x and y are
> finite, x is negative, and y is not an integer then pow(x, y) is undefined,
> and raises ValueError.
>  Changed in version 2.6: The outcome of 1**nan and nan**0 was undefined.
>
> math.sqrt(x)
>  Return the square root of x.
>

--
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090113/9052aad9/attachment.htm>


More information about the Tutor mailing list