I need to calculate exp(x**2)
where x = numpy.arange(30,90)
. This raises the warning:
RuntimeWarning: overflow encountered in exp
inf
I cannot safely ignore this warning, but neither SymPy nor mpmath is a solution and I need to perform array operations so a Numpy solution would be my dream.
Does anyone know how to handle this problem?
You could use a data type that has the necessary range, for example decimal.Decimal
:
>>> import numpy as np
>>> from decimal import Decimal
>>> x = np.arange(Decimal(30), Decimal(90))
>>> y = np.exp(x ** 2)
>>> y[-1]
Decimal('1.113246031563799750400684712E+3440')
But what are you using these numbers for? Could you avoid the exponentiation and work with logarithms? More detail about your problem would be helpful.
I think you can use this method to solve this problem:
Normalized
I overcome the problem in this method. Before using this method, my classify accuracy is :86%. After using this method, my classify accuracy is :96%!!!
It's great!
first:
Min-Max scaling
second:
Z-score standardization
These are common methods to implement normalization
.
I use the first method. And I alter it. The maximum number is divided by 10.
So the maximum number of the result is 10. Then exp(-10) will be not overflow
!
I hope my answer will help you !(^_^)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With