What I am doing now is:
import numpy as npeps = np.finfo(float).epsdef sindiv(x):x = np.abs(x)return np.maximum(eps, np.sin(x)) / np.maximum(eps, x)
But there is quite a lot of additional array operation. Is there a better way?
What I am doing now is:
import numpy as npeps = np.finfo(float).epsdef sindiv(x):x = np.abs(x)return np.maximum(eps, np.sin(x)) / np.maximum(eps, x)
But there is quite a lot of additional array operation. Is there a better way?
You could use numpy.sinc
, which computes sin(pi x)/(pi x):
In [20]: x = 2.4In [21]: np.sin(x)/x
Out[21]: 0.28144299189631289In [22]: x_over_pi = x / np.piIn [23]: np.sinc(x_over_pi)
Out[23]: 0.28144299189631289In [24]: np.sinc(0)
Out[24]: 1.0