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)
| 614 | |
| 615 | @array_function_dispatch(_flatnonzero_dispatcher) |
| 616 | def 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 | |
| 656 | def _correlate_dispatcher(a, v, mode=None): |