If I define the following function:
def f(x):
if x<1.:
return 0.
else:
return x
and I try to apply it to an array (in order to have another array as output)
import numpy as np
X=np.linspace(0.,2.,100)
print f(X)
it returns the following error:
ValueError: The truth value of an array with
more than one element is ambiguous. Use a.any() or a.all()
Of course I could solve the problem by applying the function to each component of the array separately, but it doesn't seem to be the most efficient way. What is the right way to define the function?