In the numpy array notation (so you return the np array):
def sindiv(x):
return np.where(np.abs(x) < 0.01, 1.0 - x*x/6.0, np.sin(x)/x)
Here I made the epsilon big enough for testing and used the first two members of the Taylor series to get closer. In practice, I would change 0.01 to a small multiple of yours eps(machine epsilon).
xx = np.arange(-0.1, 0.1, 0.001)
yy = sinxdiv(xx)
type(yy)
numpy.ndarray, ( , ) .
(.. ), , , , - "".
def sindiv(x):
sox = np.zeros(x.size)
for i in xrange(x.size):
xv = x[i]
if np.abs(xv) < 0.001:
sox[i] = 1.0 - xv * xv / 6.0
else:
sox[i] = np.sin(xv) / xv
return sox
pythonic, x , .