0

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 this causing an overflow?

I get this error:

OverflowError: math range error

2 Answers 2

2

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().)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but when I do numpy.exp([[-20.7313399283991]]), I get another error... stackoverflow.com/questions/24467970/…
1

You should call it without the [[]]:

e2 = math.exp(-20.7313399283991)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.