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

Function flatnotmasked_edges

numpy/ma/extras.py:1869–1922  ·  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

1867
1868
1869def flatnotmasked_edges(a):
1870 """
1871 Find the indices of the first and last unmasked values.
1872
1873 Expects a 1-D `MaskedArray`, returns None if all values are masked.
1874
1875 Parameters
1876 ----------
1877 a : array_like
1878 Input 1-D `MaskedArray`
1879
1880 Returns
1881 -------
1882 edges : ndarray or None
1883 The indices of first and last non-masked value in the array.
1884 Returns None if all values are masked.
1885
1886 See Also
1887 --------
1888 flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges
1889 clump_masked, clump_unmasked
1890
1891 Notes
1892 -----
1893 Only accepts 1-D arrays.
1894
1895 Examples
1896 --------
1897 >>> import numpy as np
1898 >>> a = np.ma.arange(10)
1899 >>> np.ma.flatnotmasked_edges(a)
1900 array([0, 9])
1901
1902 >>> mask = (a < 3) | (a > 8) | (a == 5)
1903 >>> a[mask] = np.ma.masked
1904 >>> np.array(a[~a.mask])
1905 array([3, 4, 6, 7, 8])
1906
1907 >>> np.ma.flatnotmasked_edges(a)
1908 array([3, 8])
1909
1910 >>> a[:] = np.ma.masked
1911 >>> print(np.ma.flatnotmasked_edges(a))
1912 None
1913
1914 """
1915 m = getmask(a)
1916 if m is nomask or not np.any(m):
1917 return np.array([0, a.size - 1])
1918 unmasked = np.flatnonzero(~m)
1919 if len(unmasked) > 0:
1920 return unmasked[[0, -1]]
1921 else:
1922 return None
1923
1924
1925def 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…