How to extract specific values using NumPy?

Extracting Values using NumPy.

1 Like

NumPy.extract(condition, arr)[[source]](https://github.com/numpy/numpy/blob/v1.18.1/numpy/lib/function_base.py#L1628-L1677)

Return the elements of an array that satisfy some condition.

Example:-

    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])
1 Like