title: Plotting a lambda with embedded if statement in Python using pyplot
body: <p>I want to do something like this:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  xpts = np.linspace(0, 100, 1000)
  test = lambda x: 0.5 if x &gt; 66 else 1.0
  plt.plot(xpts, test(xpts))
  </code></pre>
  
  <p>but I get the error: </p>
  
  <blockquote>
    <p>ValueError: The truth value of an array with more than one element is
    ambiguous. Use a.any() or a.all()</p>
  </blockquote>
  
  <p>On the other hand, I am able to do:</p>
  
  <pre><code>print(test(50), test(70))
  </code></pre>
  
  <blockquote>
    <p>1.0 0.5</p>
  </blockquote>
  
  <p>Why is this happening and is there a solution?</p>