I have the following code
x = -10
for i in range(2,10):
print i, " | ",np.exp(-x**i)
with the following output:
2 | 3.72007597602e-44
3 | inf
4 | 0.0
5 | inf
6 | 0.0
7 | inf
8 | 0.0
9 | inf
Why is the results ~0 for i
even and Inf
for i
odd?
Since
x = -10
,x**i
will alternate between positive and negative high values, and so will-(x**i)
which is what is calulated when you write-x**i
.np.exp(inf) = inf
andnp.exp(-inf) = 0
so for high enough numbers, you're alternating between infinity and 0.You probably wanted to write
np.exp((-x)**i)
, which will make the power index always positive.