On Tue, Jan 13, 2009 at 10:19 AM, culpritNr1 <ig2ar-s...@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
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor