title: how do I add a 'RowNumber' field to a structured numpy array?
body: <p>I am using genfromtxt to load large csv files into structured arrays. I need to sort the data (using multiple fields), do some work and then restore the data to the original ordering. My plan is to add another field to the data and put the row number into this field before the first sort is applied. It can then be used to revert the order at the end. I thought there might be an elegant way of adding this field of record numbers but after hours of trying and searching for ideas I have nothing particularly slick.</p>
  
  <pre><code>import numpy
  import numpy.lib.recfunctions as rfn
  def main():
      csvDataFile = 'C:\\File1.csv'
      csvData = numpy.genfromtxt(csvDataFile, delimiter=',',names = True, dtype='f8')
      rowNums = numpy.zeros(len(csvData),dtype=[('RowID','f8')])
      #populate and add column for RowID
      for i in range (0, len(csvData)):
          rowNums['RowID'][i]=i
      csvDataWithID = rfn.merge_arrays((csvData, rowNums), asrecarray=True, flatten=True)
  </code></pre>
  
  <p>The 
      recfunctions.merge_arrays 
  in particular is very slow and adding the row numbers one by one seems so old school. Your ideas would be gratefully received.</p>