{"id":9963,"date":"2021-03-13T09:30:34","date_gmt":"2021-03-13T04:00:34","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=9963"},"modified":"2026-07-13T12:32:37","modified_gmt":"2026-07-13T07:02:37","slug":"numpy-percentile","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/numpy-percentile\/","title":{"rendered":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> np.percentile() reports a value at a requested percentage of a data distribution. The result depends on q, the reduced axis, the interpolation method, and the treatment of NaN values, so record those choices with the statistic instead of treating a percentile as a universal single answer.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-b092.png\" alt=\"Python Pool infographic showing NumPy percentile q axis method keepdims and NaN handling\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>A percentile is a distribution summary; q, axis, method, and NaN policy determine what the reported value means.<\/figcaption><\/figure>\n<p><code>numpy.percentile()<\/code> calculates percentile cut points from an array. A percentile answers the question: what value is at or below a given percentage of the data?<\/p>\n<p>The official NumPy documentation covers <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.percentile.html\">numpy.percentile()<\/a>, <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.nanpercentile.html\">numpy.nanpercentile()<\/a>, and <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.quantile.html\">numpy.quantile()<\/a>.<\/p>\n<p>Percentiles are useful for summaries that should not depend only on the average. They are common in performance metrics, score reports, data quality checks, latency dashboards, and outlier review.<\/p>\n<p>The median is the 50th percentile. The 25th and 75th percentiles are often used to describe the middle spread of a dataset. Higher percentiles such as the 90th, 95th, and 99th help summarize tail behavior.<\/p>\n<p>The most important choices are the percentile number <code>q<\/code>, the axis, and the calculation method. Pick those choices deliberately so the output matches the question being asked.<\/p>\n<p>Percentiles do not say how many data points exist above a threshold by themselves. They give a cut point based on rank. To count how many values exceed that cut point, calculate the percentile first and then compare the array with the returned value.<\/p>\n<p>For reports, label the percentile clearly. A 95th percentile latency, a 95th percentile score, and a 95th percentile file size can all have different business meanings even though the NumPy call looks similar.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Calculate_One_Percentile\" >Calculate One Percentile<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Calculate_Several_Percentiles\" >Calculate Several Percentiles<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Use_axis_For_Columns\" >Use axis For Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Use_axis_For_Rows\" >Use axis For Rows<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Choose_A_Percentile_Method\" >Choose A Percentile Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Ignore_NaN_Values\" >Ignore NaN Values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Common_percentile_Mistakes\" >Common percentile Mistakes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Choose_q_And_The_Output_Shape\" >Choose q And The Output Shape<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Select_The_Axis_That_Represents_Samples\" >Select The Axis That Represents Samples<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Understand_Method_Differences\" >Understand Method Differences<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Handle_NaN_Values_Explicitly\" >Handle NaN Values Explicitly<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Test_Known_Distributions\" >Test Known Distributions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#How_do_I_calculate_a_percentile_with_NumPy\" >How do I calculate a percentile with NumPy?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#What_is_the_difference_between_percentile_and_quantile\" >What is the difference between percentile and quantile?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#How_do_I_ignore_NaN_values\" >How do I ignore NaN values?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/#Why_does_NumPy_return_an_unexpected_shape\" >Why does NumPy return an unexpected shape?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Calculate_One_Percentile\"><\/span>Calculate One Percentile<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Pass an array and one percentile number to <code>np.percentile()<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nscores = np.array([10, 20, 30, 40, 50])\n\nresult = np.percentile(scores, 50)\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>This prints the 50th percentile, which is the median for this sorted set of scores.<\/p>\n<p>The input does not have to be sorted. NumPy handles the calculation internally.<\/p>\n<p>Use this form when you need one summary point such as the median, 90th percentile, or 95th percentile.<\/p>\n<p>For small arrays, the selected method can affect the exact answer. For large arrays, method differences may be smaller, but they should still be consistent across repeated reports.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Calculate_Several_Percentiles\"><\/span>Calculate Several Percentiles<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Pass a list of percentile numbers to get several cut points at once.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nscores = np.array([10, 20, 30, 40, 50])\n\nquartiles = np.percentile(scores, [25, 50, 75])\n\nprint(quartiles)\n<\/code><\/pre>\n<\/div>\n<p>This returns the 25th, 50th, and 75th percentiles.<\/p>\n<p>Several percentiles are useful for box plots, summary tables, and quick distribution checks.<\/p>\n<p>Keep the requested percentiles in ascending order when the output will be read by people. NumPy returns results in the same order you request.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/percentile-ordered-b168.png\" alt=\"Python Pool infographic showing sorted observations, rank position, percentile, and quantile\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Ordered data: Sorted observations, rank position, percentile, and quantile.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_axis_For_Columns\"><\/span>Use axis For Columns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>axis=0<\/code> to calculate percentiles down each column of a two-dimensional array.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\ndata = np.array([\n    [10, 80],\n    [20, 85],\n    [30, 90],\n])\n\nresult = np.percentile(data, 50, axis=0)\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>Each column gets its own percentile value.<\/p>\n<p>This is useful when columns represent separate measurements, features, or metrics.<\/p>\n<p>Without an axis, NumPy flattens the input before calculating the percentile. That is a different question from a per-column summary.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_axis_For_Rows\"><\/span>Use axis For Rows<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>axis=1<\/code> to calculate percentiles across each row.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\ndata = np.array([\n    [10, 20, 30],\n    [40, 50, 60],\n])\n\nresult = np.percentile(data, 50, axis=1)\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>Each row gets its own median.<\/p>\n<p>This is useful when each row is a separate record and the columns are repeated measurements for that record.<\/p>\n<p>Always check the array shape before choosing an axis. A correct formula with the wrong axis can still return a plausible but misleading result.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Choose_A_Percentile_Method\"><\/span>Choose A Percentile Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>method<\/code> argument controls how NumPy handles percentile positions that fall between two data points.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\nscores = np.array([1, 2, 10, 20])\n\nlinear = np.percentile(scores, 25, method=\"linear\")\nnearest = np.percentile(scores, 25, method=\"nearest\")\n\nprint(linear)\nprint(nearest)\n<\/code><\/pre>\n<\/div>\n<p>The method choice affects results for small datasets and for percentiles that do not land exactly on an existing point.<\/p>\n<p>Use the default unless your project, report, or statistical process requires a specific percentile definition.<\/p>\n<p>When sharing results, document the method so another person can reproduce the same numbers.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/percentile-method-b168.png\" alt=\"Python Pool infographic comparing linear, lower, higher, midpoint, nearest, and interpolation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Percentile method: Linear, lower, higher, midpoint, nearest, and interpolation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Ignore_NaN_Values\"><\/span>Ignore NaN Values<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>np.nanpercentile()<\/code> when missing values are represented by <code>nan<\/code> and should be ignored.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import numpy as np\n\ndata = np.array([10, 20, np.nan, 40, 50])\n\nresult = np.nanpercentile(data, 50)\n\nprint(result)\n<\/code><\/pre>\n<\/div>\n<p>This calculates the percentile using only the non-NaN values.<\/p>\n<p>If you use <code>np.percentile()<\/code> on data containing <code>nan<\/code>, the result may also be <code>nan<\/code>. Use the NaN-aware function only when ignoring missing values is the intended rule.<\/p>\n<p>Do not silently ignore missing values in reports unless that behavior is documented. The difference can change the meaning of the summary.<\/p>\n<p>If missing values indicate failed measurements, skipped rows, or incomplete records, decide whether ignoring them is appropriate before calculating the percentile. The correct choice depends on the data source, not only on NumPy syntax.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_percentile_Mistakes\"><\/span>Common percentile Mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first common mistake is using the wrong scale for <code>q<\/code>. <code>np.percentile()<\/code> expects values from <code>0<\/code> to <code>100<\/code>. Use <code>np.quantile()<\/code> when you want the <code>0<\/code> to <code>1<\/code> scale.<\/p>\n<p>The second mistake is forgetting the axis. Flattened percentiles, per-column percentiles, and per-row percentiles answer different questions.<\/p>\n<p>The third mistake is treating percentile output as exact for every statistical convention. Different tools may use different methods, so match the method when comparing results.<\/p>\n<p>In short, use <code>np.percentile(data, q)<\/code> for percentile cut points, pass several <code>q<\/code> values for summaries, use <code>axis<\/code> for row or column summaries, and use <code>np.nanpercentile()<\/code> when missing values should be skipped.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/percentile-axis-b168.png\" alt=\"Python Pool infographic mapping rows, columns, axis, keepdims, and percentile output shape\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Axis percentile: Rows, columns, axis, keepdims, and percentile output shape.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Choose_q_And_The_Output_Shape\"><\/span>Choose q And The Output Shape<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>q is expressed from 0 to 100 for percentile, while quantile uses 0 to 1. A scalar q usually removes the selected axis; an array of q values adds a leading dimension. Use keepdims=True when the reduced dimensions must remain for broadcasting into later calculations.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Select_The_Axis_That_Represents_Samples\"><\/span>Select The Axis That Represents Samples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For a matrix, decide whether rows or columns are the observations before calling percentile. axis=0 computes a result for each column, while axis=1 computes one for each row. A wrong axis can produce plausible numbers with the wrong statistical meaning.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Understand_Method_Differences\"><\/span>Understand Method Differences<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When the requested position falls between data points, the method controls how the value is selected or interpolated. Use a named method supported by the NumPy version in your environment and record it in reproducible analysis; do not rely on an implicit default when results are contractual.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/percentile-check-b168.png\" alt=\"Python Pool infographic testing NaN, empty arrays, weights, outliers, dtype, and limits\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Quantile checks: NaN, empty arrays, weights, outliers, dtype, and limits.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Handle_NaN_Values_Explicitly\"><\/span>Handle NaN Values Explicitly<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>np.percentile() propagates NaN values in affected slices, while np.nanpercentile() ignores NaNs where possible. Decide what an all-NaN or empty slice means and test warnings, output values, and shape before publishing a metric.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Test_Known_Distributions\"><\/span>Test Known Distributions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Test minimum and maximum percentiles, repeated values, even and odd sample counts, multiple q values, each axis, keepdims, NaNs, empty input, and integer or floating data. Compare a small hand-calculated fixture with a documented method so future library upgrades are visible.<\/p>\n<p>The official <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.percentile.html\">numpy.percentile reference<\/a> documents q, axis, method, and keepdims. The <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.nanpercentile.html\">nanpercentile reference<\/a> covers missing values. Related guidance includes <a href=\"https:\/\/www.pythonpool.com\/numpy-axis\/\">axis selection<\/a> and <a href=\"https:\/\/www.pythonpool.com\/python-testing-framework\/\">numeric tests<\/a>.<\/p>\n<p>For related numerical summaries, compare <a href=\"https:\/\/www.pythonpool.com\/numpy-axis\/\">axis choices<\/a>, <a href=\"https:\/\/www.pythonpool.com\/numpy-magnitude\/\">array reductions<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/python-testing-framework\/\">numeric tests<\/a> when documenting a percentile result.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_calculate_a_percentile_with_NumPy\"><\/span>How do I calculate a percentile with NumPy?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Call np.percentile(array, q) with q between 0 and 100, or use a selected axis and method for multidimensional data.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_percentile_and_quantile\"><\/span>What is the difference between percentile and quantile?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>percentile expresses q on a 0-to-100 scale, while quantile uses a 0-to-1 scale; otherwise they describe corresponding distribution positions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_ignore_NaN_values\"><\/span>How do I ignore NaN values?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use np.nanpercentile() when NaN values should be omitted, and document what an all-NaN slice should return in the application.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_does_NumPy_return_an_unexpected_shape\"><\/span>Why does NumPy return an unexpected shape?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The q and axis arguments control the output dimensions; use keepdims=True when reduced axes must remain for broadcasting.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"How do I calculate a percentile with NumPy?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Call np.percentile(array, q) with q between 0 and 100, or use a selected axis and method for multidimensional data.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between percentile and quantile?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"percentile expresses q on a 0-to-100 scale, while quantile uses a 0-to-1 scale; otherwise they describe corresponding distribution positions.\"}},{\"@type\":\"Question\",\"name\":\"How do I ignore NaN values?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use np.nanpercentile() when NaN values should be omitted, and document what an all-NaN slice should return in the application.\"}},{\"@type\":\"Question\",\"name\":\"Why does NumPy return an unexpected shape?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The q and axis arguments control the output dimensions; use keepdims=True when reduced axes must remain for broadcasting.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.<\/p>\n","protected":false},"author":17,"featured_media":33922,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1495],"tags":[3719,3717,3718],"class_list":["post-9963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-percentile-calculator-numpy","tag-percentile-numpy","tag-python-numpy-percentile","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>NumPy percentile(): Quantiles, Axis, Methods, and NaN Values<\/title>\n<meta name=\"description\" content=\"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/numpy-percentile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values\" \/>\n<meta property=\"og:description\" content=\"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/numpy-percentile\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-13T04:00:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T07:02:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-b092.png\" \/>\n<meta name=\"author\" content=\"Siddharth Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-b092.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/\"},\"author\":{\"name\":\"Siddharth Jain\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/75a3240fabe5ea90200777a9d8d3b4fa\"},\"headline\":\"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values\",\"datePublished\":\"2021-03-13T04:00:34+00:00\",\"dateModified\":\"2026-07-13T07:02:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/\"},\"wordCount\":1215,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-percentile-guide-pythonpool.png\",\"keywords\":[\"percentile calculator numpy\",\"percentile numpy\",\"python numpy percentile\"],\"articleSection\":[\"Numpy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/\",\"name\":\"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-percentile-guide-pythonpool.png\",\"datePublished\":\"2021-03-13T04:00:34+00:00\",\"dateModified\":\"2026-07-13T07:02:37+00:00\",\"description\":\"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-percentile-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/numpy-percentile-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"NumPy percentile guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/numpy-percentile\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/75a3240fabe5ea90200777a9d8d3b4fa\",\"name\":\"Siddharth Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"caption\":\"Siddharth Jain\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values","description":"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/numpy-percentile\/","og_locale":"en_US","og_type":"article","og_title":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values","og_description":"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.","og_url":"https:\/\/www.pythonpool.com\/numpy-percentile\/","og_site_name":"Python Pool","article_published_time":"2021-03-13T04:00:34+00:00","article_modified_time":"2026-07-13T07:02:37+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-b092.png","type":"","width":"","height":""}],"author":"Siddharth Jain","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-b092.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Siddharth Jain","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/"},"author":{"name":"Siddharth Jain","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa"},"headline":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values","datePublished":"2021-03-13T04:00:34+00:00","dateModified":"2026-07-13T07:02:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/"},"wordCount":1215,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-guide-pythonpool.png","keywords":["percentile calculator numpy","percentile numpy","python numpy percentile"],"articleSection":["Numpy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/numpy-percentile\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/","url":"https:\/\/www.pythonpool.com\/numpy-percentile\/","name":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-guide-pythonpool.png","datePublished":"2021-03-13T04:00:34+00:00","dateModified":"2026-07-13T07:02:37+00:00","description":"Calculate NumPy percentiles with q, axis, method, keepdims, and nanpercentile while understanding interpolation, shapes, and missing values.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/numpy-percentile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/numpy-percentile-guide-pythonpool.png","width":1350,"height":650,"caption":"NumPy percentile guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/numpy-percentile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"NumPy percentile(): Quantiles, Axis, Methods, and NaN Values"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa","name":"Siddharth Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","caption":"Siddharth Jain"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=9963"}],"version-history":[{"count":20,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9963\/revisions"}],"predecessor-version":[{"id":41599,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9963\/revisions\/41599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/33922"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=9963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=9963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=9963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}