Q:

compare the value and print

I want to read out certain lines from this ASCII file below, and save it to another file. for an example I want to read out the rows started from column 2 which has value 17. If column 2 has value 17, then only that row goes to the output file.  
So far I have a code below,
import numpy as np
datafilename = 'pol_17.txt'
g = np.genfromtxt(datafilename, skiprows=6, usecols=(1, 2, 3, 4, 5, 6,7),delimiter=None, dtype=[('f0', '<i4'), ('f1', '<i4'), ('f2', '<i4'), ('f3', '<f8'), ('f4', '<f8'), ('f5', '<f8'), ('f6', '<f8')])
if g['f0']==17:
    print[g]

In the output, I am getting "ValueError:" from python.
The input file format is as below.
# Energy  = 4.92758E+03 
# ESigma  = 2.80000E+00 
# ETrans  = 3.78310E+02 
# Density = 1.00000E+00 
# IDR     = -1 

  7    16     0 -1  6.49729E+03  5.59241E-04  1.177E+00  4.511E-01
  7    16     1 -1  6.47947E+03  4.05646E-05  1.177E+00  4.511E-01
  7    17     0 -1  6.50710E+03  7.44345E-02  8.230E-01 -6.451E-01
  7    17     1 -1  6.48929E+03  2.11547E-03  8.230E-01 -6.451E-01
  7    17     2 -1  6.48454E+03  3.67490E-03  1.044E+00  1.271E-01
  7    17     3 -1  6.47442E+03  8.22948E-05  1.221E+00  5.434E-01
  7    18     3 -1  6.47664E+03  3.25040E-03  1.000E+00  0.000E+00
  7    18     4 -1  6.46889E+03  4.90487E-04  1.000E+00  0.000E+00
  7    18    13 -1  6.26433E+03  2.38729E-05  1.000E+00  0.000E+00
  7    18    14 -1  6.25109E+03  5.84543E-06  1.000E+00  0.000E+00

A:

A simple way to do this would be:
np.savetxt(outputfilename, g[g['f0'] == 17], fmt='%d %d %d %E% E %E %E')

where outputfilename is set to the appropriate output file name. If I were to name that file test2.dat, I get:
> cat test2.dat
17 0 -1 6.507100E+03 7.443450E-02 8.230000E-01 -6.451000E-01
17 1 -1 6.489290E+03 2.115470E-03 8.230000E-01 -6.451000E-01
17 2 -1 6.484540E+03 3.674900E-03 1.044000E+00 1.271000E-01
17 3 -1 6.474420E+03 8.229480E-05 1.221000E+00 5.434000E-01

The format string can be modified to get a particular spacing/precision in the file.

