title: Numpy: Beginner nditer
body: <p>I am trying to learn <a href="http://docs.scipy.org/doc/numpy-dev/reference/arrays.nditer.html" rel="nofollow noreferrer">nditer</a> for possible use in speeding up my application. Here, i try to make a facetious reshape program that will take a size 20 array and reshape it to a 5x4 array:</p>
  
  <pre><code>myArray = np.arange(20)
  def fi_by_fo_100(array):
      offset = np.array([0, 4, 8, 12, 16])
      it = np.nditer([offset, None],
                        flags=['reduce_ok'],
                        op_flags=[['readonly'],
                                  ['readwrite','allocate']],
                        op_axes=[None, [0,1,-1]],
                        itershape=(-1, 4, offset.size))
  
      while not it.finished:
          indices = np.arange(it[0],(it[0]+4), dtype=int)
          info = array.take(indices)
          '''Just for fun, we'll perform an operation on data.\
             Let's shift it to 100'''
          info = info + 81
          it.operands[1][...]=info
          it.iternext()
      return it.operands[1]
  
  test = fi_by_fo_100(myArray)
  &gt;&gt;&gt; test
  array([[ 97,  98,  99, 100]])
  </code></pre>
  
  <p>Clearly the program is overwriting each result into one row. So i try using the indexing functionality of nditer, but still no dice.</p>
  
  <p><code>flags=['reduce_ok','c_iter']</code> --> <code>it.operands[1][it.index][...]=info</code> =<br> <code>IndexError: index out of bounds</code></p>
  
  <p><code>flags=['reduce_ok','c_iter']</code> --> <code>it.operands[1][it.iterindex][...]=info</code> =<br> <code>IndexError: index out of bounds</code></p>
  
  <p><code>flags=['reduce_ok','multi_iter']</code> --> <code>it.operands[1][it.multi_index][...]=info</code> =<br> <code>IndexError: index out of bounds</code></p>
  
  <p><code>it[0][it.multi_index[1]][...]=info</code> = <br>
  <code>IndexError: 0-d arrays can't be indexed</code></p>
  
  <p>...and so on. What am i missing? Thanks in advance.</p>
  
  <h2>Bonus Question</h2>
  
  <p>I just happened across <a href="https://stackoverflow.com/questions/10112745/python-is-the-iteration-of-the-multidimensional-array-super-slow">this nice article on nditer</a>. I may be new to Numpy, but this is the first time i've seen Numpy speed benchmarks this far behind. It's my understanding that people choose Numpy for it's numerical speed and prowess, but iteration is a part of that, no? What is the point of nditer if it's so slow?</p>