Recently working with hdf5 format and the datasets in the format requires the arrays to be records.
What does that mean?
NumPy provides powerful capabilities to create arrays of structured datatype. These arrays permit one to manipulate the data by named fields.
One defines a structured array through the dtype object. Creating them from list is simple and take the below form
x = np.array([(1,2.,'Hello'), (2,3.,"World")], <span data-mce-type="bookmark" id="mce_SELREST_start" data-mce-style="overflow:hidden;line-height:0" style="overflow:hidden;line-height:0" ></span>dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')]) print x['foo'] array([1, 2]) print x['faz'] array(['Hello', 'World'],dtype='|S10')
But the problem with my code was that I already had arrays. So how to convert numpy arrays to numpy records arrays.
Numpy.core.records.fromarray to the rescue.
data = np.random.randn(15).reshape(5,3) rec_data = np.core.records.fromarrays(data.T, names=['a','b','c'])
Notice the transpose. That is required.