numpy.percentile() in python Last Updated : 21 Jun, 2025 Comments Improve Suggest changes Like Article Like Report numpy.percentile() compute the q-th percentile of data along the specified axis. A percentile is a measure indicating the value below which a given percentage of observations in a group falls. Example: Python import numpy as np a = np.array([1, 3, 5, 7, 9]) res = np.percentile(a, 50) print(res) Output5.0 Syntaxnumpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False, method='linear')Parameters:ParameterDescriptiona Input array or object that can be converted to an arrayqPercentile(s) to compute (0–100). Can be scalar or array-likeaxisAxis along which the percentiles are computed. Default is None (flattened)outOptional output arrayoverwrite_inputIf True, the input array can be modified for memory efficiencyinterpolation (Deprecated) Use method insteadmethodMethod to compute percentile: 'linear', 'lower', 'higher', 'midpoint', 'nearest'keepdimsIf True, the reduced axes are left in the result as dimensions with size oneReturns: The q-th percentile(s) of the array elements. If q is a list, it returns multiple percentiles.ExamplesExample 1: In this example, we compute the 25th, 50th and 75th percentiles of a 1D array. Python import numpy as np a = np.array([10, 20, 30, 40, 50]) res = np.percentile(a, [25, 50, 75]) print(res) Output[20. 30. 40.] Example 2: In this example, we compute the 50th percentile (median) along each row of a 2D array using the axis parameter. Python import numpy as np a = np.array([[10, 7, 4], [3, 2, 1]]) res = np.percentile(a, 50, axis=1) print(res) Output[7. 2.] Example 3: In this example, we compute the 50th percentile (median) using the method='lower' option. Python import numpy as np a = np.array([1, 2, 3, 4]) res = np.percentile(a, 50, method='lower') print(res) Output2 Example 4: In this example, we compute the 50th percentile (median) along each row of a 2D array and use keepdims=True to preserve the original dimensions. Python import numpy as np a = np.array([[10, 20, 30], [40, 50, 60]]) res = np.percentile(a, 50, axis=1, keepdims=True) print(res) Output[[20.] [50.]] Comment More infoAdvertise with us Next Article numpy.quantile() in Python M mohit gupta_omg :) Follow Improve Article Tags : Python Python-numpy Python numpy-Statistics Functions Practice Tags : python Similar Reads numpy.nanpercentile() in Python numpy.nanpercentile() function compute the nth percentile of the given data (array elements) along the specified axis and ignores nan values. Example:Pythonimport numpy as np a = np.array([10, 20, np.nan, 40]) res = np.nanpercentile(a, 50) print(res)Output20.0 Explanation: The 50th percentile (media 2 min read numpy.nanpercentile() in Python numpy.nanpercentile() function compute the nth percentile of the given data (array elements) along the specified axis and ignores nan values. Example:Pythonimport numpy as np a = np.array([10, 20, np.nan, 40]) res = np.nanpercentile(a, 50) print(res)Output20.0 Explanation: The 50th percentile (media 2 min read 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.floor() in Python The numpy.floor() function returns the largest integer less than or equal to each element in the input array. It effectively rounds numbers down to the nearest whole number. Let's understand with an example:Pythonimport numpy as np a = [0.5, 1.5, 2.5, 3, 4.5, 10.1] res = np.floor(a) print("Floored:" 1 min read numpy.quantile() in Python numpy.quantile() function is used to find the qth quantile, which is the value below which a given percentage q of data falls in a NumPy array. For example, it can tell you what value lies at the 25% mark of your data, what the median (50th percentile) is, or what value corresponds to the 90th perce 2 min read numpy.quantile() in Python numpy.quantile() function is used to find the qth quantile, which is the value below which a given percentage q of data falls in a NumPy array. For example, it can tell you what value lies at the 25% mark of your data, what the median (50th percentile) is, or what value corresponds to the 90th perce 2 min read Like