Skip to content Skip to sidebar Skip to footer

Math Overflow For A Not Very Overflowing Calculation In Python

The calculation for which I'm getting the math overflow number is: e2 = math.exp([[-20.7313399283991]]) There are actually more extreme numbers that I've done than this, why is th

Solution 1:

math.exp() operates on scalars, not on matrices.

You can use it like so, without the square brackets:

>>> math.exp(-20.7313399283991)
9.919584164742123e-10

If you need to operate on a matrix, you could use numpy.exp():

>>> numpy.exp([[-20.7313399283991]])
array([[  9.91958416e-10]])

This computes the element-by-element e**x and returns an array of the same shape as the input. (Note that this is not the same as the matrix exponential; for that, there is scipy.linalg.expm().)

Solution 2:

You should call it without the [[]]:

e2 = math.exp(-20.7313399283991)

Post a Comment for "Math Overflow For A Not Very Overflowing Calculation In Python"