MCPcopy Index your code
hub / github.com/numpy/numpy / fromflex

Function fromflex

numpy/ma/core.py:8749–8811  ·  view source on GitHub ↗

Build a masked array from a suitable flexible-type array. The input array has to have a data-type with ``_data`` and ``_mask`` fields. This type of array is output by `MaskedArray.toflex`. Parameters ---------- fxarray : ndarray The structured input array, containi

(fxarray)

Source from the content-addressed store, hash-verified

8747
8748
8749def fromflex(fxarray):
8750 """
8751 Build a masked array from a suitable flexible-type array.
8752
8753 The input array has to have a data-type with ``_data`` and ``_mask``
8754 fields. This type of array is output by `MaskedArray.toflex`.
8755
8756 Parameters
8757 ----------
8758 fxarray : ndarray
8759 The structured input array, containing ``_data`` and ``_mask``
8760 fields. If present, other fields are discarded.
8761
8762 Returns
8763 -------
8764 result : MaskedArray
8765 The constructed masked array.
8766
8767 See Also
8768 --------
8769 MaskedArray.toflex : Build a flexible-type array from a masked array.
8770
8771 Examples
8772 --------
8773 >>> import numpy as np
8774 >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4)
8775 >>> rec = x.toflex()
8776 >>> rec
8777 array([[(0, False), (1, True), (2, False)],
8778 [(3, True), (4, False), (5, True)],
8779 [(6, False), (7, True), (8, False)]],
8780 dtype=[('_data', '<i8'), ('_mask', '?')])
8781 >>> x2 = np.ma.fromflex(rec)
8782 >>> x2
8783 masked_array(
8784 data=[[0, --, 2],
8785 [--, 4, --],
8786 [6, --, 8]],
8787 mask=[[False, True, False],
8788 [ True, False, True],
8789 [False, True, False]],
8790 fill_value=999999)
8791
8792 Extra fields can be present in the structured array but are discarded:
8793
8794 >>> dt = [('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')]
8795 >>> rec2 = np.zeros((2, 2), dtype=dt)
8796 >>> rec2
8797 array([[(0, False, 0.), (0, False, 0.)],
8798 [(0, False, 0.), (0, False, 0.)]],
8799 dtype=[('_data', '<i4'), ('_mask', '?'), ('field3', '<f4')])
8800 >>> y = np.ma.fromflex(rec2)
8801 >>> y
8802 masked_array(
8803 data=[[0, 0],
8804 [0, 0]],
8805 mask=[[False, False],
8806 [False, False]],

Callers 1

test_fromflexMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_fromflexMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…