I want to vectorize the following function using np.vectroize:
def f(x):
if 0<=x<=1:
return 0.5
elif 1<x<=3:
return 0.25
else:
return 0
Next step:
f = np.vectorize(f)
However, if I put negative values in the input array for f, all of a sudden all the output values become zero. There is no problem when all values are positive. For example:
f([-0.1,1,2,3,4])
output is:
array([0, 0, 0, 0, 0])