Record Arrays (numpy.rec)#
Record arrays expose the fields of structured arrays as properties.
Most commonly, ndarrays contain elements of a single type, e.g. floats,integers, bools etc. However, it is possible for elements to be combinationsof these using structured types, such as:
>>>importnumpyasnp>>>a=np.array([(1,2.0),(1,2.0)],...dtype=[('x',np.int64),('y',np.float64)])>>>aarray([(1, 2.), (1, 2.)], dtype=[('x', '<i8'), ('y', '<f8')])
Here, each element consists of two fields: x (and int), and y (a float).This is known as a structured array. The different fields are analogousto columns in a spread-sheet. The different fields can be accessed asone would a dictionary:
>>>a['x']array([1, 1])
>>>a['y']array([2., 2.])
Record arrays allow us to access fields as properties:
>>>ar=np.rec.array(a)>>>ar.xarray([1, 1])>>>ar.yarray([2., 2.])
Functions#
| Construct a record array from a wide-variety of objects. |
| Find duplication in a list, return a list of duplicated elements |
| Class to convert formats, names, titles description to a dtype. |
| Create a record array from a (flat) list of arrays |
| Create an array from binary file data |
| Create a recarray from a list of records in text form. |
| Create a record array from binary data |
Also, thenumpy.recarray class and thenumpy.record scalar dtype are presentin this namespace.