Trying to compare array but getting "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"

Can someone help me understand and correct my short code for the error in the title?

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 1, 100)
a = 2

def f(x):
    if x<0.5:
        return a*x
    elif x>=0.5:
        return a*(1-x)

plt.plot(x, f(x))
plt.show()
      6 
      7 def f(x):
----> 8     if x<0.5:
      9         return a*x
     10     elif x>=0.5:


from Recent Questions - Stack Overflow https://ift.tt/3CUp9TC
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept