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 three yield the same error, please help me out
xis an array. Do you wantfto do one thing if any/all ofxfall in one range, and a different if they don't? Or do you want it to do one thing with thexvalues that fall in one range, and a different thing for the otherxvalues? In other words does theiftest apply to the whole ofxor to the individual elements?xto it individually?