MCPcopy Create free account
hub / github.com/numpy/numpy / flatnonzero

Function flatnonzero

numpy/core/numeric.py:616–653  ·  view source on GitHub ↗

Return indices that are non-zero in the flattened version of a. This is equivalent to ``np.nonzero(np.ravel(a))[0]``. Parameters ---------- a : array_like Input data. Returns ------- res : ndarray Output array, containing the indices of the element

(a)

Source from the content-addressed store, hash-verified

614
615@array_function_dispatch(_flatnonzero_dispatcher)
616def flatnonzero(a):
617 """
618 Return indices that are non-zero in the flattened version of a.
619
620 This is equivalent to ``np.nonzero(np.ravel(a))[0]``.
621
622 Parameters
623 ----------
624 a : array_like
625 Input data.
626
627 Returns
628 -------
629 res : ndarray
630 Output array, containing the indices of the elements of ``a.ravel()``
631 that are non-zero.
632
633 See Also
634 --------
635 nonzero : Return the indices of the non-zero elements of the input array.
636 ravel : Return a 1-D array containing the elements of the input array.
637
638 Examples
639 --------
640 >>> x = np.arange(-2, 3)
641 >>> x
642 array([-2, -1, 0, 1, 2])
643 >>> np.flatnonzero(x)
644 array([0, 1, 3, 4])
645
646 Use the indices of the non-zero elements as an index array to extract
647 these elements:
648
649 >>> x.ravel()[np.flatnonzero(x)]
650 array([-2, -1, 1, 2])
651
652 """
653 return np.nonzero(np.ravel(a))[0]
654
655
656def _correlate_dispatcher(a, v, mode=None):

Callers

nothing calls this directly

Calls 2

nonzeroMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected