numpy.flatnonzero() in Python Last Updated : 28 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report numpy.flatnonzero()function is used to Compute indices that are non-zero in the flattened version of arr. Syntax : numpy.flatnonzero(arr) Parameters : 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 Python # Python program explaining # flatnonzero() function import numpy as geek arr = geek.arange(-3, 4) print ("Input array : ", arr) out_arr = geek.flatnonzero(arr) print ("Indices of non zero elements : ", out_arr) Output : 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. Python # Python program using the indices of the non-zero # elements as an index array to extract these elements out_arr = arr.ravel()[geek.flatnonzero(arr)] print ("Output array of non-zero number: ", out_arr) Output : Output array of non-zero number: [-3 -2 -1 1 2 3] Comment More infoAdvertise with us Next Article numpy.asfarray() in Python J jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-Sorting Searching Practice Tags : python Similar Reads numpy.nonzero() in Python numpy.nonzero() function returns the indices of the elements in an array that are non-zero. It is commonly used to find the positions of non-zero (or True) elements in arrays.Example:Pythonimport numpy as np a = np.array([0, 2, 0, 3, 0, 4]) res = np.nonzero(a) print(res)Output(array([1, 3, 5]),) Exp 2 min read numpy.any() in Python The numpy.any() function tests whether any array elements along the mentioned axis evaluate to True. Syntax :Â numpy.any(a, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters :Â array :[array_like]Input array or object whose elements, we need to test. axis : 3 min read numpy.fabs() in Python numpy.fabs() function is used to compute the absolute values element-wise. This function returns the absolute values (positive magnitude) of the data in arr. It always return absolute values in floats. Syntax : numpy.fabs(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, u 2 min read Python | Numpy np.flatiter() method With the help of np.flatiter() method, we can get the flat iterator with the help of np.flatiter() method. Syntax : np.flatiter() Return : Return the flat iterator. Example #1 : In this example we can see that by using np.flatiter() method, we are able to get the flat iterator using this method. Pyt 1 min read numpy.asfarray() in Python numpy.asfarray()function is used when we want to convert input to a float type array. Input includes scalar, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Syntax : numpy.asfarray(arr, dtype=type 'numpy.float64') Parameters : arr : [array_like] Input data, in any for 2 min read NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read Like