I want to populate a numpy array with values from the smooth bump function
f(x) = exp ( - 1 / (1 - x^2) ) if |x| < 1, f(x) = 0 otherwise
Currently I have something that works (as in gives me the right numbers on my platform)
x = linspace(-1.1 , 1.1, 300) #Sample 300 points between [-1.1,1.1]
bump = exp( 1 - 1 / (1 - clip(square(x), 0,1)) )
when the absolute value of an entry in x is at least 1, its square gets clipped to 1, and we have "1/(1-1) = 1/0 = +inf" as "expected" on my platform, which then gets set by "exp(1 - inf) = 0" which is exactly the behaviour I want.
My questions:
- I suspect that the above is not the best practice. Am I correct in my suspicions?
- Are there better ways of handling this division by zero? At the end of the day the array
xmay not be just simply a linear list of values. So I want something that can computef(x)fromxefficiently.