Skip to content

argwhere

Find the indices of array elements that are non-zero, grouped by element.

Parameters:

Name Type Description Default
a array_like

Input data.

required

Returns:

Name Type Description
index_array ndarray
See Also

sparse.where, sparse.COO.nonzero

Examples:

>>> import sparse
>>> x = sparse.COO(np.arange(6).reshape((2, 3)))
>>> sparse.argwhere(x > 1)
array([[0, 2],
       [1, 0],
       [1, 1],
       [1, 2]])
Source code in sparse/numba_backend/_coo/common.py
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
def argwhere(a):
    """
    Find the indices of array elements that are non-zero, grouped by element.

    Parameters
    ----------
    a : array_like
        Input data.

    Returns
    -------
    index_array : numpy.ndarray

    See Also
    --------
    [`sparse.where`][], [`sparse.COO.nonzero`][]

    Examples
    --------
    >>> import sparse
    >>> x = sparse.COO(np.arange(6).reshape((2, 3)))
    >>> sparse.argwhere(x > 1)
    array([[0, 2],
           [1, 0],
           [1, 1],
           [1, 2]])
    """
    return np.transpose(a.nonzero())