I would like to use special scipy functions to work with extremely large numbers
alpha = 9999
def y(t):
return 1 / (special.lambertw(alpha * math.exp(alpha-t)) + 1)
math.exp
causes an overflow error, which is not surprising. So I tried using a decimal module instead
alpha = 9999
def y(t):
exp = decimal.Decimal(math.exp(1))
exp = exp ** alpha
exp = exp * decimal.Decimal(math.exp(-t))
return 1 / (special.lambertw(alpha * math.exp(alpha-t)) + 1)
But get the following error:
TypeError: ufunc '_lambertw' not supported for the input types, and the
inputs could not be safely coerced to any supported types according to
the casting rule ''safe''
special.lambertw
comes from scipy
What would be the right way to handle this?
source
share