Home > Net >  matplotlib different values for y function
matplotlib different values for y function

Time:10-21

I need to make plot for: enter image description here

alternatively, you can use numpy.vectorize or another solution posted here.

CodePudding user response:

You see the error because the result of x<0 gives multiple boolean (one per each element of x). Hence the if cannot resolve whether the condition is true or false.

In your case, you can simply compute y and then change its values based on conditions on x:

x=np.arange(-2, 2, 1)
y=np.exp(x)-1

# check content of y
print(y)


y[x<0]=0

# check updated content of y
print(y)
  • Related