MCPcopy
hub / github.com/dask/dask / compress

Function compress

dask/array/routines.py:2017–2044  ·  view source on GitHub ↗
(condition, a, axis=None)

Source from the content-addressed store, hash-verified

2015
2016@derived_from(np)
2017def compress(condition, a, axis=None):
2018 if not is_arraylike(condition):
2019 # Allow `condition` to be anything array-like, otherwise ensure `condition`
2020 # is a numpy array.
2021 condition = np.asarray(condition)
2022 condition = condition.astype(bool)
2023 a = asarray(a)
2024
2025 if condition.ndim != 1:
2026 raise ValueError("Condition must be one dimensional")
2027
2028 if axis is None:
2029 a = a.ravel()
2030 axis = 0
2031 axis = validate_axis(axis, a.ndim)
2032
2033 # Treat `condition` as filled with `False` (if it is too short)
2034 a = a[
2035 tuple(
2036 slice(None, len(condition)) if i == axis else slice(None)
2037 for i in range(a.ndim)
2038 )
2039 ]
2040
2041 # Use `condition` to select along 1 dimension
2042 a = a[tuple(condition if i == axis else slice(None) for i in range(a.ndim))]
2043
2044 return a
2045
2046
2047@derived_from(np)

Callers 3

test_read_textFunction · 0.85
extractFunction · 0.85
argwhereFunction · 0.85

Calls 5

is_arraylikeFunction · 0.90
asarrayFunction · 0.90
validate_axisFunction · 0.90
astypeMethod · 0.45
ravelMethod · 0.45

Tested by 1

test_read_textFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…