title: How to convert an array of strings to a record array?
body: <p>This is similar to <a href="https://stackoverflow.com/q/3877209/327026">How to convert an array of strings to an array of floats in numpy</a>.</p>
  
  <p>I have a list of strings:</p>
  
  <pre><code>dat = [
      '  1  2  1.040000e+005  0.030000\n',
      '  2  7  0.000000e+000  0.030000\n',
      '  3  15  0.000000e+000  0.030000\n',
  ]
  </code></pre>
  
  <p>Here are my failed attempts to make a numpy record array:</p>
  
  <pre><code>import numpy as np
  dat_dtype = [
      ('I', 'i'),
      ('J', 'i'),
      ('val1', 'd'),
      ('val2', 'd'),
  ]
  
  # Attempt 1
  np.array(dat, dat_dtype)
  # looks like garbage
  
  # Attempt 2
  np.array([x.split() for x in dat], dtype=dat_dtype)
  # looks like different garbage
  
  # Attempt 3
  string_ndarray = np.array([x.split() for x in dat], dtype='|S15')
  # looks good so far
  string_ndarray.astype(dat_dtype)
  Traceback (most recent call last):
    File "&lt;interactive input&gt;", line 1, in &lt;module&gt;
  ValueError: invalid literal for int() with base 10: '1.040000e+005'
  </code></pre>
  
  <p>I give up. Here's the only way I can get the expected output:</p>
  
  <pre><code>dat_ndarray = np.zeros(len(dat), dat_dtype)
  for i, line in enumarate(dat):
      dat_ndarray[i] = tuple(line.split())
  
  print(dat_ndarray)  # [(1, 2, 104000.0, 0.03) (2, 7, 0.0, 0.03) (3, 15, 0.0, 0.03)]
  </code></pre>
  
  <p>Is there a more direct method to get the expected record array?</p>