def y(x):
if x <0:
return np.cos(x)
else:
np.exp(-x)
x = np.arange(-2*np.pi,2*np.pi,0.1)
plt.plot(x,y(x))
plt.show()
This function supposed to plot y (x) as cos (x) if the x value is less than zero, otherwise exp (-x).
I wrote the code, but it gave me an error. How I can fix the error?
I get this error
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()