This is a pre-release version (latest).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / extract

_ArrayFunctionDispatcher

numpy:extract

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py:2043

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_like

An array whose nonzero or True entries indicate the elements of arr to extract.

arr : array_like

Input array of the same size as condition.

Returns

extract : ndarray

Rank 1 array of values from arr where condition is 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)
✓
array([0, 3, 6, 9])
If `condition` is boolean:
arr[condition]
✓
array([0, 3, 6, 9])

See also

compress
copyto
place
put
take

Aliases

  • numpy.extract