title: Python numpy savetxt not saving: "tuple index out of range"
body: <p>Hi I wrote the following python code that (supposedly) extracts data from a FITS file. </p>
  
  <pre><code>target_array=np.loadtxt(target_list)
  N=len(target_array)
  target=['target_{0}.fits'.format(i) for i in range(1,N+1,1)]
  hdu=[]
  hdudata=[]
  for i in range(N):
  hdu.append(pyfits.open(target[i]))
  hdudata.append(hdu[i][1].data)
  f=[]
  for i in range(N):
      for j in range(len(hdudata[i])):
          if dist(target_array[i][0],hdudata[i][j]['Ra'],target_array[i][1],hdudata[i][j]['Dec']) &lt;= func(hdudata[i][j]['Energy']):
                              f.append(hdudata[i][j]['Energy'])
          print "Target", i, "successfully stacked"
  
  np.savetxt('energy_stack.txt',f)
  </code></pre>
  
  <p>target_array is a N x 2 array containing the coordinates for the target of interest. Each target FITS file contains thousands of 'events' that are linked to a specific coordinates and energy. The code cycles through each event in each target and grabs the energy for events that meet a criteria (the distance between the the target coordinates and the event coordinates must be less then some specified number), if it meets the criteria it is saved to "f" which is a 1D array, a simple list of numbers (about 23000 numbers).</p>
  
  <p>Everything works up until the savetxt command and then it spits the error:</p>
  
  <pre><code>    Traceback (most recent call last):
    File "pipe_stack.py", line 184, in &lt;module&gt;
      get_target_energy('target_list_reduced.txt')
    File "pipe_stack.py", line 132, in get_target_energy
      np.savetxt('energy_stack.txt',f)
    File "/home/heatdeath/fermi_science/ScienceTools-v10r0p5-fssc-20150518A-source/external/x86_64-unknown-linux-gnu-libc2.19-0/lib/python2.7/site-packages/numpy/lib/npyio.py", line 1118, in savetxt
      ncol = X.shape[1]
  IndexError: tuple index out of range
  </code></pre>
  
  <p>I need to know what is going wrong. This code worked for a different sample.</p>