Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
numpy.percentile() in python
Next article icon

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) 

Output
5.0 

Syntax

numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False, method='linear')

Parameters:

Parameter

Description

a

Input array or object that can be converted to an array

q

Percentile(s) to compute (0–100). Can be scalar or array-like

axis

Axis along which the percentiles are computed. Default is None (flattened)

out

Optional output array

overwrite_input

If True, the input array can be modified for memory efficiency

interpolation

(Deprecated) Use method instead

method

Method to compute percentile: 'linear', 'lower', 'higher', 'midpoint', 'nearest'

keepdims

If True, the reduced axes are left in the result as dimensions with size one

Returns: The q-th percentile(s) of the array elements. If q is a list, it returns multiple percentiles.

Examples

Example 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) 

Output
2 

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.]] 

Next Article
numpy.percentile() in python

M

mohit gupta_omg :)
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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences