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

Function notmasked_edges

numpy/ma/extras.py:1925–1974  ·  view source on GitHub ↗

Find the indices of the first and last unmasked values along an axis. If all values are masked, return None. Otherwise, return a list of two tuples, corresponding to the indices of the first and last unmasked values respectively. Parameters ---------- a : array_like

(a, axis=None)

Source from the content-addressed store, hash-verified

1923
1924
1925def notmasked_edges(a, axis=None):
1926 """
1927 Find the indices of the first and last unmasked values along an axis.
1928
1929 If all values are masked, return None. Otherwise, return a list
1930 of two tuples, corresponding to the indices of the first and last
1931 unmasked values respectively.
1932
1933 Parameters
1934 ----------
1935 a : array_like
1936 The input array.
1937 axis : int, optional
1938 Axis along which to perform the operation.
1939 If None (default), applies to a flattened version of the array.
1940
1941 Returns
1942 -------
1943 edges : ndarray or list
1944 An array of start and end indexes if there are any masked data in
1945 the array. If there are no masked data in the array, `edges` is a
1946 list of the first and last index.
1947
1948 See Also
1949 --------
1950 flatnotmasked_contiguous, flatnotmasked_edges, notmasked_contiguous
1951 clump_masked, clump_unmasked
1952
1953 Examples
1954 --------
1955 >>> import numpy as np
1956 >>> a = np.arange(9).reshape((3, 3))
1957 >>> m = np.zeros_like(a)
1958 >>> m[1:, 1:] = 1
1959
1960 >>> am = np.ma.array(a, mask=m)
1961 >>> np.array(am[~am.mask])
1962 array([0, 1, 2, 3, 6])
1963
1964 >>> np.ma.notmasked_edges(am)
1965 array([0, 6])
1966
1967 """
1968 a = asarray(a)
1969 if axis is None or a.ndim == 1:
1970 return flatnotmasked_edges(a)
1971 m = getmaskarray(a)
1972 idx = array(np.indices(a.shape), mask=np.asarray([m] * a.ndim))
1973 return [tuple(idx[i].min(axis).compressed() for i in range(a.ndim)),
1974 tuple(idx[i].max(axis).compressed() for i in range(a.ndim)), ]
1975
1976
1977def flatnotmasked_contiguous(a):

Callers 1

test_edgesMethod · 0.90

Calls 7

flatnotmasked_edgesFunction · 0.85
getmaskarrayFunction · 0.85
asarrayFunction · 0.70
arrayFunction · 0.70
compressedMethod · 0.45
minMethod · 0.45
maxMethod · 0.45

Tested by 1

test_edgesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…