title: Why doesn't chained (interval) comparison work on numpy arrays?
body: <p><code>a &lt; b &lt; c</code> is an <a href="https://docs.python.org/2.7/reference/expressions.html#comparisons" rel="noreferrer">chained expression</a> in Python, and it looks like it works on objects with appropriate comparison operators defined, but it doesn't work on numpy arrays. Why?</p>
  
  <pre><code>import numpy as np
  
  class ContrarianContainer(object):
      def __init__(self, x):
          self.x = x
      def __le__(self, y):
          return not self.x &lt;= y
      def __lt__(self, y):
          return not self.x &lt; y
      def __ge__(self, y):
          return not self.x &gt;= y
      def __gt__(self, y):
          return not self.x &gt; y
      def __eq__(self, y):
          return not self.x == y
      def __ne__(self, y):
          return not self.x != y
  
  numlist = np.array([1,2,3,4])
  for n in numlist:
      print 0 &lt; n &lt; 3.5
  for n in numlist:
      print 0 &gt; ContrarianContainer(n) &gt; 3.5
  print 0 &lt; numlist &lt; 3.5
  </code></pre>
  
  <p>this prints:</p>
  
  <pre><code>True
  True
  True
  False
  True
  True
  True
  False
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-187-277da7750148&gt; in &lt;module&gt;()
        4 for n in numlist:
        5     print 0 &lt; n &lt; 3.5
  ----&gt; 6 print 0 &lt; numlist &lt; 3.5
  
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>