This gives me an error:
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
I don't know why this should fail?
Alternatlively, how can I force something like this statement to work?
x = np.array([[1, 'O', 1]])
then
x.dtype = np.dtype([('step', 'int32'),('symbol', '|S1'),('index', 'int32')])
or
x.view(dtype=np.dtype([('step', 'int32'),('symbol', '|S1'),('index', 'int32')]))
both give me
ValueError: new type not compatible with array.
Edit
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:
import numpy as np
x = np.array([(1, 'O', 1)],
dtype=np.dtype([('step', 'int32'),
('symbol', '|S1'),
('index', 'int32')]))
seems fine until I do this:
import numpy.lib.recfunctions as rec
rec.append_fields(x,'x',x['index']+1)
gives me
TypeError: object of type 'numpy.int32' has no len()
presumably because x.shape is (1,) rather than (1,3).