numpy.nanpercentile() in Python Last Updated : 01 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report numpy.nanpercentile() function compute the nth percentile of the given data (array elements) along the specified axis and ignores nan values. Example: Python import numpy as np a = np.array([10, 20, np.nan, 40]) res = np.nanpercentile(a, 50) print(res) Output20.0 Explanation: The 50th percentile (median) is calculated over [10, 20, 40], ignoring the NaN.Syntaxnumpy.nanpercentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=<no value>, method='linear')Parameters:ParameterDescriptionaInput array.qPercentile or sequence of percentiles (between 0 and 100).axisAxis along which percentiles are computed. Default is None (entire array).outAlternative output array.overwrite_inputIf True, allows modifying input array (for memory efficiency).interpolation[Deprecated] Use method instead.keepdimsIf True, retains reduced dimensions.methodSpecifies interpolation method (e.g., 'linear', 'nearest', 'lower', 'higher', 'midpoint'). Default: 'linear'.Returns: A scalar or ndarray of percentiles, depending on q and axis.ExamplesExample 1: Computing multiple percentiles Python import numpy as np a = np.array([5, 15, np.nan, 25]) res = np.nanpercentile(a, [25, 50, 75]) print(res) Output[10. 15. 20.] Explanation: Calculates the 25th, 50th, and 75th percentiles of the non-NaN values.Example 2: Applying along a specific axis Python import numpy as np a = np.array([[10, 20, np.nan], [30, np.nan, 50]]) res = np.nanpercentile(a, 50, axis=0) print(res) Output[20. 20. 50.] Explanation: The median of each column is computed by ignoring NaN values. Column 0: median(10, 30) = 20Column 1: median(20) = 20Column 2: median(50) = 50.Example 3: Using different interpolation method Python import numpy as np a = np.array([1, 2, 3, 4, 5, np.nan]) res = np.nanpercentile(a, 40, method='nearest') print(res) Output3.0 Explanation: With method='nearest', the function picks the value nearest to the 40th percentile position. Comment More infoAdvertise with us Next Article numpy.nanargmin() in Python M mohit gupta_omg :) Follow Improve Article Tags : Python Python-numpy Python numpy-Statistics Functions Practice Tags : python Similar Reads numpy.nanquantile() in Python numpy.nanquantile(arr, q, axis = None) : Compute the qth quantile of the given data (array elements) along the specified axis, ignoring the nan values. Quantiles plays a very important role in statistics. In the figure given above, Q2 is the median and Q3 - Q1 represents the Interquartile Range of 4 min read numpy.nanprod() in Python numpy.nanprod() function computes the product of array elements over a given axis while treating NaN (Not a Number) values as 1 (i.e., ignoring them in the product). Example:Pythonimport numpy as np a = np.array([1.0, 2.0, np.nan, 4.0]) res = np.nanprod(a) print(res)Output8.0 Explanation: np.nanprod 2 min read numpy.nanmin() in Python numpy.nanmin()function is used when to returns minimum value of an array or along any specific mentioned axis of the array, ignoring any Nan value. Syntax : numpy.nanmin(arr, axis=None, out=None) Parameters : arr :Input array. axis :Axis along which we want the min value. Otherwise, it will consider 2 min read numpy.nanvar() in Python numpy.nanvar(arr, axis = None) : Compute the variance of the given data (array elements) along the specified axis(if any), while ignoring NaN values. Example : x = 1 1 1 1 1 Standard Deviation = 0 . Variance = 0 y = 9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4 Step 1 : Mean of dist 3 min read numpy.nanargmin() in Python The numpy.nanargmin() function returns indices of the min element of the array in a particular axis ignoring NaNs. The results cannot be trusted if a slice contains only NaNs and Infs. Syntax:  numpy.nanargmin(array, axis = None) Parameters : array : Input array to work on axis : [int, optional]A 2 min read 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 Like