title: Python – ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
body: <p>I'm really new to programming, and I can't figure out how to use a Numpy array to be manipulated in a function such as <code>P**2</code>.</p>
  
  <pre><code>import math
  import numpy
  span_x = numpy.array([0,250,500,750,1000])
  P = span_x
  example = P**2
  span_y = [example for i in P]
  y = float(input("Enter y: "))
  bracket1 = min(span_y, lambda span_y: abs(span_y-y))
  if bracket1 &lt; y:
      for i in span_y:
          bracket2 = span_y[span_y.index(bracket1) + 1]
  else:
      for i in span_y:
          bracket2 = span_y[span_y.index(bracket1) - 1]
  print "Brackets: ", bracket1, bracket2
  </code></pre>
  
  <p>I've tried not using a Numpy array, but received a TypeError.</p>
  
  <p>My main issue is that I have this array of x-values (<code>span_x</code>) that I want to put into a function like <code>P**2</code> and get y-values (<code>span_y</code>) in an array. Then, the user inputs a y-value and I want to check which y-value in <code>span_y</code> is closest to this input, and that is <code>bracket1</code>. <code>bracket2</code> is the second closest y-value. I would love some help!</p>