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.percentile() 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 used to compute the nth percentile of the given data (array elements) along the specified axis and ignores nan values. Syntax : numpy.nanpercentile(arr, q, axis=None, out=None) Parameters : arr :input array. q : percentile value. axis :axis along which we want to calc 4 min read numpy.std() in Python numpy.std() is a function provided by the NumPy library that calculates the standard deviation of an array or a set of values. Standard deviation is a measure of the amount of variation or dispersion of a set of values.\text{Standard Deviation} = \sqrt{\text{mean} \left( (x - x.\text{mean}())^2 \rig 3 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.round_() in Python The round_() function in NumPy rounds the elements of an array to a specified number of decimal places. This function is extremely useful when working with floating-point numbers and when precision is important in scientific computing or data analysis.Syntax: numpy.round_(arr, decimals=0, out=None)P 3 min read Like