[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/../generated/numpy.rec.format_parser.html [Back]  [Original]

numpy.rec.format_parser — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.rec.format_parser#

class numpy.rec.format_parser(formats, names, titles, aligned=False, byteorder=None)[source]#

Class to convert formats, names, titles description to a dtype.

After constructing the format_parser object, the dtype attribute is the converted data-type: dtype = format_parser(formats, names, titles).dtype

Parameters:
formatsstr or list of str

The format description, either specified as a string with comma-separated format descriptions in the form 'f8, i4, S5', or a list of format description strings in the form ['f8', 'i4', 'S5'].

namesstr or list/tuple of str

The field names, either specified as a comma-separated string in the form 'col1, col2, col3', or as a list or tuple of strings in the form ['col1', 'col2', 'col3']. An empty list can be used, in that case default field names (f0, f1, ) are used.

titlessequence

Sequence of title strings. An empty list can be used to leave titles out.

alignedbool, optional

If True, align the fields by padding as the C-compiler would. Default is False.

byteorderstr, optional

If specified, all the fields will be changed to the provided byte-order. Otherwise, the default byte-order is used. For all available string specifiers, see dtype.newbyteorder.

Attributes:
dtypedtype

The converted data-type.

Examples

Try it in your browser!
>>> import numpy as np
>>> np.rec.format_parser(['<f8', '<i4'], ['col1', 'col2'],
...                      ['T1', 'T2']).dtype
dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4')])

names and/or titles can be empty lists. If titles is an empty list, titles will simply not appear. If names is empty, default field names will be used.

>>> np.rec.format_parser(['f8', 'i4', 'S5'], ['col1', 'col2', 'col3'],
...                      []).dtype
dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
>>> np.rec.format_parser(['<f8', '<i4', '<S5'], [], []).dtype
dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])

Web Proxy Viewer  |  New URL  |  Original Page