title: How does the axis parameter from NumPy work?
body: <p>Can someone explain exactly what the <code>axis</code> parameter in NumPy does?</p>
  
  <p>I am terribly confused. </p>
  
  <p>I'm trying to use the function <code>myArray.sum(axis=num)</code></p>
  
  <p>At first I thought if the array is itself 3 dimensions, <code>axis=0</code> will return three elements, consisting of the sum of all nested items in that same position. If each dimension contained five dimensions, I expected <code>axis=1</code> to return a result of five items, and so on. </p>
  
  <p>However this is not the case, and the documentation does not do a good job helping me out <a href="http://pages.citebite.com/n2u9w2x6t5efl" rel="noreferrer">(they use a 3x3x3 array so it's hard to tell what's happening)</a></p>
  
  <p>Here's what I did:</p>
  
  <pre><code>&gt;&gt;&gt; e
  array([[[1, 0],
          [0, 0]],
  
         [[1, 1],
          [1, 0]],
  
         [[1, 0],
          [0, 1]]])
  &gt;&gt;&gt; e.sum(axis = 0)
  array([[3, 1],
         [1, 1]])
  &gt;&gt;&gt; e.sum(axis=1)
  array([[1, 0],
         [2, 1],
         [1, 1]])
  &gt;&gt;&gt; e.sum(axis=2)
  array([[1, 0],
         [2, 1],
         [1, 1]])
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Clearly the result is not intuitive.</p>