dask.array.compress — Dask documentation (original) (raw)
Return selected slices of an array along given axis.
This docstring was copied from numpy.compress.
Some inconsistencies with the Dask version may exist.
When working along a given axis, a slice along that axis is returned inoutput for each index where condition evaluates to True. When working on a 1-D array, compress is equivalent to extract.
import numpy as np
a = np.array([[1, 2], [3, 4], [5, 6]])
a
array([[1, 2], [3, 4], [5, 6]]) np.compress([0, 1], a, axis=0)
array([[3, 4]]) np.compress([False, True, True], a, axis=0)
array([[3, 4], [5, 6]]) np.compress([False, True], a, axis=1)
array([[2], [4], [6]])
Working on the flattened array does not return slices along an axis but selects elements.
np.compress([False, True], a)
array([2])