title: How to create a numpy record array?
body: <p>This gives me an error:</p>
  
  <pre><code>import numpy as np
  x = np.array([[1, 'O', 1]],
               dtype=np.dtype([('step', 'int32'),
                               ('symbol', '|S1'),
                               ('index', 'int32')]))
  
  TypeError: expected a readable buffer object
  </code></pre>
  
  <p>I don't know why this should fail?</p>
  
  <p>Alternatlively, how can I force something like this statement to work?</p>
  
  <pre><code>x = np.array([[1, 'O', 1]])
  </code></pre>
  
  <p>then</p>
  
  <pre><code>x.dtype = np.dtype([('step', 'int32'),('symbol', '|S1'),('index', 'int32')])
  </code></pre>
  
  <p>or </p>
  
  <pre><code>x.view(dtype=np.dtype([('step', 'int32'),('symbol', '|S1'),('index', 'int32')]))
  </code></pre>
  
  <p>both give me</p>
  
  <pre><code>ValueError: new type not compatible with array.
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>If I try to enter each record as a tuple, it will think that the triple is a single value, rather than three separate fields? For instance:</p>
  
  <pre><code>import numpy as np
  x = np.array([(1, 'O', 1)],
               dtype=np.dtype([('step', 'int32'),
                               ('symbol', '|S1'),
                               ('index', 'int32')]))
  </code></pre>
  
  <p>seems fine until I do this:</p>
  
  <pre><code>import numpy.lib.recfunctions as rec
  rec.append_fields(x,'x',x['index']+1)
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code>TypeError: object of type 'numpy.int32' has no len()
  </code></pre>
  
  <p>presumably because <code>x.shape</code> is (1,) rather than (1,3).</p>