I'm very confused as to what np.exp() actually does. In the documentation it says that it: "Calculates the exponential of all elements in the input array." I'm confused as to what exactly this means. Could someone give me more information to what it actually does?
What exactly does numpy.exp() do?
Asked Answered
The exponential function is e^x
where e
is a mathematical constant called Euler's number, approximately 2.718281
. This value has a close mathematical relationship with pi
and the slope of the curve e^x
is equal to its value at every point. np.exp()
calculates e^x
for each value of x
in your input array.
It calculates ex for each x in your list where e is Euler's number (approximately 2.718). In other words, np.exp(range(5))
is similar to [math.e**x for x in range(5)]
.
For beginner:
math.e
is the Euler's number. Try import math; print(math.e) # 2.718281828459045
. And **
is Python code for power. –
Debris exp(x) = e^x where e= 2.718281(approx)
In Python we can use the exp
function from numpy
(docs):
import numpy as np
ar=np.array([1,2,3])
ar=np.exp(ar)
print ar
outputs:
[ 2.71828183 7.3890561 20.08553692]
Your code gives me following error: ufunc 'exp' output (typecode 'd') could not be coerced to provided output parameter (typecode 'l') according to the casting rule ''same_kind'" –
Sinclare
If you change the [1,2,3] to [1.,2.,3.], the error should disappear. I think it happens because of a conversion of the numpy values to object type. So you put them as float, and it works :) or maybe it happens only in Python 2x, I tested in python 3.6 and it worked. –
Scopoline
assert np.exp(np.log(2.5)) == 2.5
–
Underestimate © 2022 - 2024 — McMap. All rights reserved.
print np.arange(10), np.exp(np.arange(10))
(for python2). – Diseur