numpyExt module

Extensions to NumPy used by several programs.

Module author: Michael S. Chapman <chapmanms@missouri.edu>

Module author: Brynmor K. Chapman

Authors:

Michael S. Chapman <chapmanms@missouri.edu>

Oregon Health & Science University & University of Missouri

Version:

1, Nov 26, 2024

Changed in version 04/25/13.

Changed in version 0.5.0: (5/1/15) ReStructured Text documentation

Changed in version 1.0.0: 11/17/20 Python 2.7 –> 3.6

Deprecated since version 1.0.0: As of 11/18/20, it looks like this has not been imported by other modules for a while.

class numpyExt.Flagged(data, mask=None, use=None, **args)

Bases: MaskedArray, object

Array with elements designated to be used (or skipped).

Subclass of NumPy.MaskedArray with extensions to support assignment, selection and iteration over elements designated as used (or masked). Note: use is an added antonym for mask, i.e. its complement.

The most succinct way to (in)activate elements in an existing instance f, is with the assignments: f[slice] = f.inactive eg. f[:3] = f.inactive, and: f[slice] = f.data[slice]. These are variants of the recommendations for MaskedArray (masking with special assignment to numpy.ma.masked), noting an important difference. In a masked array, the presumption is that masked elements are invalid data and can be reactivated by assignment to any valid value. In Flagged, there is no such presumption, and previously inactivated elements may be needed again, so the activating assignment should always assign to the corresponding element(s) of the data attribute.

Warning

an assignment to an inactive element makes it active, eg. instance[i] = 2, activates element i! To avoid this, assign instance.data[i].

Array from data with mask designating use.

Parameters:
  • data (ndarray) – array

  • use (sequence mappable into boolean array of same shape as data) – elements to be used in calculations

  • mask (sequence mappable into boolean array of same shape as data) – elements hidden from calculations. Complement of “use”. Provide only one of “use” or “skip”.

  • args (dict) – key-word arguments to be passed to MaskedArray, including, but not limited to (see documentation): copy=False: make a new copy of data, instead of addressing a previously created ndarray; fill_value=scalar: for starting values of skipped elements.

inactive = masked
iteritems()

Index and value for each used element.

Returns:

(index, value).

Return type:

tuple(int, float)

set_unused_values(values)

Set only used elements to value(s).

Parameters:

values – sequence or single value to broadcast.

Returns:

self with reassigned elements.

Return type:

Masked

set_used_values(values)

Set only used elements to value(s).

Parameters:

values – sequence or single value to broadcast.

Returns:

self with reassigned elements.

Return type:

Masked

property skip

Logical array denoting unused elements (ndarray(dtype=bool)).

property skipped

Indices of unused elements (ndarray, or tuple of ndarray for multidimensional).

property use

Logical array denoting used elements (ndarray(dtype=bool)).

property used

Indices of used elements (ndarray, or tuple of ndarray for multidimensional).

property value

View of used data, containing only elements in use (ndarray(ndim=1).

numpyExt.testFlagged()