I'm trying to employ some models using python / numpy of the form:
f(x) = 1 / (exp(x) - 1)
where x can be any value from -5 to +5 say.
x can be zero and during my simulations this does occur, causing f(x) to tend to infinity, which returns a nan + 1jnan.
Since I then want to use the results from this calculation later on, e.g. to FFT, this creates a major problem, since the fft routine can't handle NANs in the input.
Are there any recommended ways of dealing with this please? e.g. putting logic to say: if x == 0: return 0 or e.g. shifting x by 0.00000001% if it equals zero, to avoid this problem.
Thanks
You can simply avoid this problem by using a continue statement:
Here, whenever the value of x = 0 occurs, the loop simply avoids the f(x) function and iterates to the next value.