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

Function _ezclump

numpy/ma/extras.py:2110–2136  ·  view source on GitHub ↗

Finds the clumps (groups of data with the same values) for a 1D bool array. Returns a series of slices.

(mask)

Source from the content-addressed store, hash-verified

2108
2109
2110def _ezclump(mask):
2111 """
2112 Finds the clumps (groups of data with the same values) for a 1D bool array.
2113
2114 Returns a series of slices.
2115 """
2116 if mask.ndim > 1:
2117 mask = mask.ravel()
2118 idx = (mask[1:] ^ mask[:-1]).nonzero()
2119 idx = idx[0] + 1
2120
2121 if mask[0]:
2122 if len(idx) == 0:
2123 return [slice(0, mask.size)]
2124
2125 r = [slice(0, idx[0])]
2126 r.extend((slice(left, right)
2127 for left, right in zip(idx[1:-1:2], idx[2::2])))
2128 else:
2129 if len(idx) == 0:
2130 return []
2131
2132 r = [slice(left, right) for left, right in zip(idx[:-1:2], idx[1::2])]
2133
2134 if mask[-1]:
2135 r.append(slice(idx[-1], mask.size))
2136 return r
2137
2138
2139def clump_unmasked(a):

Callers 2

clump_unmaskedFunction · 0.85
clump_maskedFunction · 0.85

Calls 3

sliceFunction · 0.85
nonzeroMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…