title: In numpy, what does indexing an array with the empty tuple vs. ellipsis do?
body: <p>I just discovered — by chance — that an array in <code>numpy</code> may be indexed by an empty tuple:</p>
  
  <pre><code>In [62]: a = arange(5)
  
  In [63]: a[()]
  Out[63]: array([0, 1, 2, 3, 4])
  </code></pre>
  
  <p>I found some documentation on the <a href="http://projects.scipy.org/numpy/wiki/ZeroRankArray" rel="noreferrer">numpy wiki ZeroRankArray</a>:</p>
  
  <blockquote>
    <p>(Sasha) First, whatever choice is made for x[...] and x[()] they should be the same because ... is just syntactic sugar for "as many : as necessary", which in the case of zero rank leads to ... = (:,)*0 = (). Second, rank zero arrays and numpy scalar types are interchangeable within numpy, but numpy scalars can be use in some python constructs where ndarrays can't.</p>
  </blockquote>
  
  <p>So, for 0-d arrays <code>a[()]</code> and <code>a[...]</code> are supposed to be equivalent. Are they for higher-dimensional arrays, too? They strongly appear to be:</p>
  
  <pre><code>In [65]: a = arange(25).reshape(5, 5)
  
  In [66]: a[()] is a[...]
  Out[66]: False
  
  In [67]: (a[()] == a[...]).all()
  Out[67]: True
  
  In [68]: a = arange(3**7).reshape((3,)*7)
  
  In [69]: (a[()] == a[...]).all()
  Out[69]: True
  </code></pre>
  
  <p><strong>But</strong>, it is <em>not</em> syntactic sugar. Not for a high-dimensional array, and not even for a 0-d array:</p>
  
  <pre><code>In [76]: a[()] is a
  Out[76]: False
  
  In [77]: a[...] is a
  Out[77]: True
  
  In [79]: b = array(0)
  
  In [80]: b[()] is b
  Out[80]: False
  
  In [81]: b[...] is b
  Out[81]: True
  </code></pre>
  
  <p>And then there is the case of indexing by an empty <em>list</em>, which does something else altogether, but appears equivalent to indexing with an empty <code>ndarray</code>:</p>
  
  <pre><code>In [78]: a[[]]
  Out[78]: array([], shape=(0, 3, 3, 3, 3, 3, 3), dtype=int64)
  
  In [86]: a[arange(0)]
  Out[86]: array([], shape=(0, 3, 3, 3, 3, 3, 3), dtype=int64)
  
  In [82]: b[[]]
  ---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  
  IndexError: 0-d arrays can't be indexed.
  </code></pre>
  
  <p>So, it appears that <code>()</code> and <code>...</code> are similar but not quite identical and indexing with <code>[]</code> means something else altogether. And <code>a[]</code> or <code>b[]</code> are <code>SyntaxError</code>s. Indexing with lists is documented at <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#index-arrays" rel="noreferrer">index arrays</a>, and there is a short notice about indexing with tuples <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#dealing-with-variable-numbers-of-indices-within-programs" rel="noreferrer">at the end of the same document</a>.</p>
  
  <p>That leaves the question:</p>
  
  <p>Is the difference between <code>a[()]</code> and <code>a[...]</code> by design? What is the design, then? </p>
  
  <p>(Question somehow reminiscent of: <a href="https://stackoverflow.com/q/13679749/974555">What does the empty `()` do on a Matlab matrix?</a>)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>In fact, even <em>scalars</em> may be indexed by an empty tuple:</p>
  
  <pre><code>In [36]: numpy.int64(10)[()]
  Out[36]: 10
  </code></pre>