numpy.flatnonzero()function is used to Compute indices that are non-zero in the flattened version of arr.
Syntax : numpy.flatnonzero(arr)
arr : [array_like] Input array.
Return : ndarray
Output array, containing the indices of the elements of arr.ravel() that are non-zero.
Code #1 : Working
Input array : [-3 -2 -1 0 1 2 3] Indices of non zero elements : [0 1 2 4 5 6]
Code #2 : Using the indices of the non-zero elements as an index array.
Output array of non-zero number: [-3 -2 -1 1 2 3]
- Important differences between Python 2.x and Python 3.x with examples
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Reading Python File-Like Objects from C | Python
- Python | Merge Python key values to list
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- zip() in Python
- SQL using Python | Set 1
- Use of min() and max() in Python
- Python Set | pop()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.