module documentation

numpy.ma..mrecords

Defines the equivalent of numpy.recarrays for masked arrays, where fields can be accessed as attributes. Note that numpy.ma.MaskedArray already supports structured datatypes and the masking of individual fields.

Variable reserved​_fields Undocumented
Class ​Masked​Records No summary
Function ​_checknames Checks that field names descr are not reserved keywords.
Function ​_get​_fieldmask Undocumented
Function ​_guessvartypes Tries to guess the dtypes of the str_ ndarray arr.
Function ​_mrreconstruct Build a new MaskedArray from the information stored in a pickle.
Function addfield Adds a new field to the masked record array
Function fromarrays Creates a mrecarray from a (flat) list of masked arrays.
Function fromrecords Creates a MaskedRecords from a list of records.
Function fromtextfile Creates a mrecarray from data stored in the file filename.
Function openfile Opens the file handle of file fname.
reserved_fields: list[str] =

Undocumented

def _checknames(descr, names=None):

Checks that field names descr are not reserved keywords.

If this is the case, a default 'f%i' is substituted. If the argument names is not None, updates the field names to valid names.

def _get_fieldmask(self):

Undocumented

def _guessvartypes(arr):

Tries to guess the dtypes of the str_ ndarray arr.

Guesses by testing element-wise conversion. Returns a list of dtypes. The array is first converted to ndarray. If the array is 2D, the test is performed on the first line. An exception is raised if the file is 3D or more.

def _mrreconstruct(subtype, baseclass, baseshape, basetype):
Build a new MaskedArray from the information stored in a pickle.
def addfield(mrecord, newfield, newfieldname=None):

Adds a new field to the masked record array

Uses newfield as data and newfieldname as name. If newfieldname is None, the new field name is set to 'fi', where i is the number of existing fields.

def fromarrays(arraylist, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None, fill_value=None):

Creates a mrecarray from a (flat) list of masked arrays.

Parameters

arraylist : sequence
A list of (masked) arrays. Each element of the sequence is first converted to a masked array if needed. If a 2D array is passed as argument, it is processed line by line
dtype : {None, dtype}, optional
Data type descriptor.
shape : {None, integer}, optional
Number of records. If None, shape is defined from the shape of the first array in the list.
formats : {None, sequence}, optional
Sequence of formats for each individual field. If None, the formats will be autodetected by inspecting the fields and selecting the highest dtype possible.
names : {None, sequence}, optional
Sequence of the names of each field.
fill_value : {None, sequence}, optional
Sequence of data to be used as filling values.

Notes

Lists of tuples should be preferred over lists of lists for faster processing.

def fromrecords(reclist, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None, fill_value=None, mask=nomask):

Creates a MaskedRecords from a list of records.

Parameters

reclist : sequence
A list of records. Each element of the sequence is first converted to a masked array if needed. If a 2D array is passed as argument, it is processed line by line
dtype : {None, dtype}, optional
Data type descriptor.
shape : {None,int}, optional
Number of records. If None, shape is defined from the shape of the first array in the list.
formats : {None, sequence}, optional
Sequence of formats for each individual field. If None, the formats will be autodetected by inspecting the fields and selecting the highest dtype possible.
names : {None, sequence}, optional
Sequence of the names of each field.
fill_value : {None, sequence}, optional
Sequence of data to be used as filling values.
mask : {nomask, sequence}, optional.
External mask to apply on the data.

Notes

Lists of tuples should be preferred over lists of lists for faster processing.

def fromtextfile(fname, delimiter=None, commentchar='#', missingchar='', varnames=None, vartypes=None, *, delimitor=np._NoValue):

Creates a mrecarray from data stored in the file filename.

Parameters

fname : {file name/handle}
Handle of an opened file.
delimiter : {None, string}, optional
Alphanumeric character used to separate columns in the file. If None, any (group of) white spacestring(s) will be used.
commentchar : {'#', string}, optional
Alphanumeric character used to mark the start of a comment.
missingchar : {'', string}, optional
String indicating missing data, and used to create the masks.
varnames : {None, sequence}, optional
Sequence of the variable names. If None, a list will be created from the first non empty line of the file.
vartypes : {None, sequence}, optional
Sequence of the variables dtypes. If None, it will be estimated from the first non-commented line.

Ultra simple: the varnames are in the header, one line

def openfile(fname):
Opens the file handle of file fname.