The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
although I know there's various questions looking for solutions to this error message, I've yet to find an answer that helps me solve my code to get the comparison working, I have the code def f(x,d,h,L): ans=0. if ((0.<=x) & (x<d)): ans=h*(x/d) elif ((d<=x) & (x<=L)): ans=((L-x)/(L-d)) return ans x=np.linspace(0,10,1000) h=5*10**(-3) d=16*10**(-2) L=64.52*10**(-2) func=f(x,d,h,L) But when I try running it I get an error pointing to the if line with the error code in the title, I've tried the proposed solutions given in similar questions such as using np.logical_and or and instead of & but all