title: dtype for integer, three floats
body: <p>I have a text file that, amongst other data, contains data of the form</p>
  
  <pre><code>215
  1 0.0 0.0 0.0
  [...]
  9 -0.4330127018930699 0.2499999999985268 1.0
  10 -0.1366025403783193 -0.03660254037890862 1.0
  11 -0.2499999999985268 -0.4330127018930699 1.0
  12 0.03660254037890862 -0.1366025403783193 1.0
  13 0.4330127018930699 -0.2499999999985268 1.0
  14 0.1366025403783193 0.03660254037890862 1.0
  15 0.2499999999985268 0.4330127018930699 1.0
  [...]
  215 1.0 1.0 1.0
  [...]  # some more data, other format
  </code></pre>
  
  <p>i.e.,</p>
  
  <ul>
  <li>an integer specifying the number of rows of data to come,</li>
  <li>N rows with an integer followed by three floats,</li>
  <li>some more data, formatted differently.</li>
  </ul>
  
  <p>I would like to convert these data into a numpy array. Since I can best access the file with a generator over the lines, <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromiter.html" rel="nofollow"><code>numpy.fromiter()</code></a> comes in handy. I fail to specify the data type correctly, though. This</p>
  
  <pre class="lang-py prettyprint-override"><code>with open(filename) as f:
      line = islice(f, 1).next()
      num_nodes = int(line)
      points = numpy.fromiter(
          islice(f, num_nodes),
          dtype=[('idx', int, 1), ('vals', float, 3)],
          count=num_nodes
          )
  </code></pre>
  
  <p>does <em>not</em> work. Any hints?</p>