MCPcopy Create free account
hub / github.com/numpy/numpy / flatnotmasked_edges

Function flatnotmasked_edges

numpy/ma/extras.py:1733–1785  ·  view source on GitHub ↗

Find the indices of the first and last unmasked values. Expects a 1-D `MaskedArray`, returns None if all values are masked. Parameters ---------- a : array_like Input 1-D `MaskedArray` Returns ------- edges : ndarray or None The indices of first an

(a)

Source from the content-addressed store, hash-verified

1731
1732
1733def flatnotmasked_edges(a):
1734 """
1735 Find the indices of the first and last unmasked values.
1736
1737 Expects a 1-D `MaskedArray`, returns None if all values are masked.
1738
1739 Parameters
1740 ----------
1741 a : array_like
1742 Input 1-D `MaskedArray`
1743
1744 Returns
1745 -------
1746 edges : ndarray or None
1747 The indices of first and last non-masked value in the array.
1748 Returns None if all values are masked.
1749
1750 See Also
1751 --------
1752 flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges
1753 clump_masked, clump_unmasked
1754
1755 Notes
1756 -----
1757 Only accepts 1-D arrays.
1758
1759 Examples
1760 --------
1761 >>> a = np.ma.arange(10)
1762 >>> np.ma.flatnotmasked_edges(a)
1763 array([0, 9])
1764
1765 >>> mask = (a < 3) | (a > 8) | (a == 5)
1766 >>> a[mask] = np.ma.masked
1767 >>> np.array(a[~a.mask])
1768 array([3, 4, 6, 7, 8])
1769
1770 >>> np.ma.flatnotmasked_edges(a)
1771 array([3, 8])
1772
1773 >>> a[:] = np.ma.masked
1774 >>> print(np.ma.flatnotmasked_edges(a))
1775 None
1776
1777 """
1778 m = getmask(a)
1779 if m is nomask or not np.any(m):
1780 return np.array([0, a.size - 1])
1781 unmasked = np.flatnonzero(~m)
1782 if len(unmasked) > 0:
1783 return unmasked[[0, -1]]
1784 else:
1785 return None
1786
1787
1788def notmasked_edges(a, axis=None):

Callers 1

notmasked_edgesFunction · 0.85

Calls 2

getmaskFunction · 0.85
anyMethod · 0.45

Tested by

no test coverage detected