dask.array.extract — Dask documentation (original) (raw)
Return the elements of an array that satisfy some condition.
This docstring was copied from numpy.extract.
Some inconsistencies with the Dask version may exist.
This is equivalent to np.compress(ravel(condition), ravel(arr))
. Ifcondition is boolean np.extract
is equivalent to arr[condition]
.
Note that place does the exact opposite of extract.
import numpy as np
arr = np.arange(12).reshape((3, 4))
arr
array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) condition = np.mod(arr, 3)==0
condition
array([[ True, False, False, True], [False, False, True, False], [False, True, False, False]]) np.extract(condition, arr)
array([0, 3, 6, 9])
arr[condition]
array([0, 3, 6, 9])