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.

Class MaskedRecords No summary
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.
Variable reserved_fields Undocumented
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.
def addfield(mrecord, newfield, newfieldname=None): (source)

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): (source)

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

Notes

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

Parameters
arraylist:sequenceA 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}, optionalData type descriptor.
shape:{None, integer}, optionalNumber of records. If None, shape is defined from the shape of the first array in the list.
formats:{None, sequence}, optionalSequence 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}, optionalSequence of the names of each field.
titlesUndocumented
alignedUndocumented
byteorderUndocumented
fill_value:{None, sequence}, optionalSequence of data to be used as filling values.
def fromrecords(reclist, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None, fill_value=None, mask=nomask): (source)

Creates a MaskedRecords from a list of records.

Notes

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

Parameters
reclist:sequenceA 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}, optionalData type descriptor.
shape:{None, int}, optionalNumber of records. If None, shape is defined from the shape of the first array in the list.
formats:{None, sequence}, optionalSequence 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}, optionalSequence of the names of each field.
titlesUndocumented
alignedUndocumented
byteorderUndocumented
fill_value:{None, sequence}, optionalSequence of data to be used as filling values.
mask:{nomask, sequence}, optional.External mask to apply on the data.
def fromtextfile(fname, delimiter=None, commentchar='#', missingchar='', varnames=None, vartypes=None, *, delimitor=np._NoValue): (source)

Creates a mrecarray from data stored in the file filename.

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

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

Opens the file handle of file fname.

reserved_fields: list[str] = (source)

Undocumented

def _checknames(descr, names=None): (source)

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): (source)

Undocumented

def _guessvartypes(arr): (source)

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): (source)

Build a new MaskedArray from the information stored in a pickle.