title: How does NumPy multidimensional array iteration work? (With and without nditer)
body: <p>Note: I am not sure if this is a duplicate or not -- please let me know if it is (and close the question).</p>
  
  <p>If one has a 1-dimensional NumPy array <code>vector</code>, then if one writes a for loop of the form:</p>
  
  <pre><code>for element in vector :
      print(element)
  </code></pre>
  
  <p>The result will print each element of the NumPy array.</p>
  
  <p>If one has a 2-dimensional NumPy array <code>matrix</code>, then if one writes a for loop of the form:  </p>
  
  <pre><code>for vector in matrix :
      print(vector)
  </code></pre>
  
  <p>The result will print each row of the 2-dimensional NumPy array, i.e. it will print 1-dimensional NumPy arrays, and it will <em>not</em> print each element of the array individually.</p>
  
  <p>However, if one instead writes the for loop as:</p>
  
  <pre><code>import numpy
  for element in numpy.nditer(matrix) :
       print(element)
  </code></pre>
  
  <p>The result <em>will</em> print each element of the 2-dimensional NumPy array.</p>
  
  <p><strong>Question:</strong> What happens if one has a 3-dimensional NumPy array, <code>tensor</code>? </p>
  
  <p><strong>a.</strong> If one writes a for loop of the form:</p>
  
  <pre><code>for unknownType in tensor :
       print(unknownType)
  </code></pre>
  
  <p>Will this print the constituent 2-dimensional NumPy (sub-)arrays of <code>tensor</code>?</p>
  
  <p>I.e. for an n-dimensional NumPy array <code>nArray</code>, does <code>for unknownType in nArray :</code> iterate over the constituent (n-1)-dimensional NumPy (sub-)arrays of <code>nArray</code>?</p>
  
  <p><strong>b.</strong> If one writes a for loop of the form:</p>
  
  <pre><code>for unknownType in numpy.nditer(tensor) :
      print(unknownType)
  </code></pre>
  
  <p>Will this print the elements of <code>tensor</code>? Or will it print the constituent 1-dimensional NumPy (sub-)arrays of the constituent 2-dimensional NumPy (sub-)arrays of <code>tensor</code>?</p>
  
  <p>I.e. for an n-dimensional NumPy array <code>nArray</code>, does <code>for unknownType in nditer(nArray) :</code> iterate over the elements of <code>nArray</code>? Or does it iterate over the constituent (n-2)-dimensional NumPy (sub-)arrays of the constituent (n-1)-dimensional NumPy (sub-)arrays of <code>nArray</code>?</p>
  
  <p>It is unclear to me from the name <code>nditer</code>, since I don't know what "nd" stands for ("iter" is obviously short for "iteration"). And presumably one can think of the elements as "0-dimensional NumPy arrays", so the examples given to me for 2-dimensional NumPy arrays are ambiguous. </p>
  
  <p>I've looked at the <a href="https://docs.scipy.org/doc/numpy/reference/arrays.nditer.html#arrays-nditer" rel="noreferrer"><code>np.nditer</code> documentation</a> but honestly I didn't understand the examples or what they were trying to demonstrate -- it seems like it was written for programmers (which I am not) by programmers.</p>