bundles / numpy 2.4.4 / numpy / extract
_ArrayFunctionDispatcher
numpy:extract
Signature
def extract ( condition , arr ) Summary
Return the elements of an array that satisfy some condition.
Extended Summary
This is equivalent to np.compress(ravel(condition), ravel(arr)). If condition is boolean np.extract is equivalent to arr[condition].
Note that place does the exact opposite of extract.
Parameters
condition: array_likeAn array whose nonzero or True entries indicate the elements of
arrto extract.arr: array_likeInput array of the same size as
condition.
Returns
extract: ndarrayRank 1 array of values from
arrwhereconditionis True.
Examples
import numpy as np arr = np.arange(12).reshape((3, 4)) arr condition = np.mod(arr, 3)==0 condition np.extract(condition, arr)✓
arr[condition]
✓See also
- compress
- copyto
- place
- put
- take
Aliases
-
numpy.extract