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)
| 673 | |
| 674 | @array_function_dispatch(_flatnonzero_dispatcher) |
| 675 | def flatnonzero(a): |
| 676 | """ |
| 677 | Return indices that are non-zero in the flattened version of a. |
| 678 | |
| 679 | This is equivalent to ``np.nonzero(np.ravel(a))[0]``. |
| 680 | |
| 681 | Parameters |
| 682 | ---------- |
| 683 | a : array_like |
| 684 | Input data. |
| 685 | |
| 686 | Returns |
| 687 | ------- |
| 688 | res : ndarray |
| 689 | Output array, containing the indices of the elements of ``a.ravel()`` |
| 690 | that are non-zero. |
| 691 | |
| 692 | See Also |
| 693 | -------- |
| 694 | nonzero : Return the indices of the non-zero elements of the input array. |
| 695 | ravel : Return a 1-D array containing the elements of the input array. |
| 696 | |
| 697 | Examples |
| 698 | -------- |
| 699 | >>> import numpy as np |
| 700 | >>> x = np.arange(-2, 3) |
| 701 | >>> x |
| 702 | array([-2, -1, 0, 1, 2]) |
| 703 | >>> np.flatnonzero(x) |
| 704 | array([0, 1, 3, 4]) |
| 705 | |
| 706 | Use the indices of the non-zero elements as an index array to extract |
| 707 | these elements: |
| 708 | |
| 709 | >>> x.ravel()[np.flatnonzero(x)] |
| 710 | array([-2, -1, 1, 2]) |
| 711 | |
| 712 | """ |
| 713 | return np.nonzero(np.ravel(a))[0] |
| 714 | |
| 715 | |
| 716 | def _correlate_dispatcher(a, v, mode=None): |