numpy.core.records.fromrecords¶
- numpy.core.records.fromrecords(recList, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None)[source]¶
create a recarray from a list of records in text form
The data in the same field can be heterogeneous, they will be promoted to the highest data type. This method is intended for creating smaller record arrays. If used to create large array without formats defined
r=fromrecords([(2,3.,’abc’)]*100000)
it can be slow.
If formats is None, then this will auto-detect formats. Use list of tuples rather than list of lists for faster processing.
>>> r=np.core.records.fromrecords([(456,'dbe',1.2),(2,'de',1.3)], ... names='col1,col2,col3') >>> print r[0] (456, 'dbe', 1.2) >>> r.col1 array([456, 2]) >>> r.col2 chararray(['dbe', 'de'], dtype='|S3') >>> import pickle >>> print pickle.loads(pickle.dumps(r)) [(456, 'dbe', 1.2) (2, 'de', 1.3)]