I'm trying to graph a function I define piecewise. As an example, take
def f(x,y):
if x in I.open(0, 1):
if y in I.open(0, 1):
return (x+y)
else:
return(0)
I then define Z as follows:
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
Z = f(X,Y)
If I run this, I get:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I've seen some answers to similar questions, but I haven't been able to fix this problem with anything I've read. I understand (I think) that the problem is in the statement if x in I.open(0,1)... since running f(X,Y) asks whether X is in I.open(0,1) and, since X is an array, this may be true for some elements of X while not true for others. But when you graph a function like, Z=X+Y, the computer has no problem determining which values of X and Y to use at each step, so why can't it do that here?

I.opensupposed to be? Please provide a reproducible example and be careful of the formatting (e.g. indentation)