<p dir="auto">Under certain settings, np.quantile makes mistakes in determining the correct quantile. Is this a bug? In the output, 0.73 means that only 73% of values are larger or equal than the determined quantile; by definition it should be &gt;= 75% for p=0.25.</p>
<p dir="auto">I know, that I can produce the correct result with np.quantile(x, 0.25, interpolation="lower") = 366, where 26% of values &lt;= 366 and 76% of values &gt;= 366. My point is, the standard version of the method delivers a result that does not fulfill the most general defintion of quantiles.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
x = np.array([374, 358, 341, 355, 342, 334, 353, 346, 355, 344,
              349, 330, 352, 328, 336, 359, 361, 345, 324, 386,
              334, 370, 349, 327, 342, 354, 361, 354, 377, 324])

q = np.quantile(x, 0.25)

print(q)

print(len(x[x&lt;=q]) / len(x))

print(len(x[x&gt;=q]) / len(x))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">374</span>, <span class="pl-c1">358</span>, <span class="pl-c1">341</span>, <span class="pl-c1">355</span>, <span class="pl-c1">342</span>, <span class="pl-c1">334</span>, <span class="pl-c1">353</span>, <span class="pl-c1">346</span>, <span class="pl-c1">355</span>, <span class="pl-c1">344</span>,
              <span class="pl-c1">349</span>, <span class="pl-c1">330</span>, <span class="pl-c1">352</span>, <span class="pl-c1">328</span>, <span class="pl-c1">336</span>, <span class="pl-c1">359</span>, <span class="pl-c1">361</span>, <span class="pl-c1">345</span>, <span class="pl-c1">324</span>, <span class="pl-c1">386</span>,
              <span class="pl-c1">334</span>, <span class="pl-c1">370</span>, <span class="pl-c1">349</span>, <span class="pl-c1">327</span>, <span class="pl-c1">342</span>, <span class="pl-c1">354</span>, <span class="pl-c1">361</span>, <span class="pl-c1">354</span>, <span class="pl-c1">377</span>, <span class="pl-c1">324</span>])

<span class="pl-s1">q</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">quantile</span>(<span class="pl-s1">x</span>, <span class="pl-c1">0.25</span>)

<span class="pl-en">print</span>(<span class="pl-s1">q</span>)

<span class="pl-en">print</span>(<span class="pl-en">len</span>(<span class="pl-s1">x</span>[<span class="pl-s1">x</span><span class="pl-c1">&lt;=</span><span class="pl-s1">q</span>]) <span class="pl-c1">/</span> <span class="pl-en">len</span>(<span class="pl-s1">x</span>))

<span class="pl-en">print</span>(<span class="pl-en">len</span>(<span class="pl-s1">x</span>[<span class="pl-s1">x</span><span class="pl-c1">&gt;=</span><span class="pl-s1">q</span>]) <span class="pl-c1">/</span> <span class="pl-en">len</span>(<span class="pl-s1">x</span>))</pre></div>

<h3 dir="auto">Numpy/Python version information:</h3>

<p dir="auto">337.25</p>
<p dir="auto">0.26666666666666666</p>
<p dir="auto">0.7333333333333333</p>
<p dir="auto">Under certain settings, np.quantile makes mistakes in determining the correct quantile. Is this a bug? In the output, 0.73 means that only 73% of values are larger or equal than the determined quantile; by definition it should be &gt;= 75% for p=0.25.</p>
<p dir="auto">I know, that I can produce the correct result with np.quantile(x, 0.25, interpolation="lower") = 366, where 26% of values &lt;= 366 and 76% of values &gt;= 366. My point is, the standard version of the method delivers a result that does not fulfill the most general defintion of quantiles.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
x = np.array([374, 358, 341, 355, 342, 334, 353, 346, 355, 344,
              349, 330, 352, 328, 336, 359, 361, 345, 324, 386,
              334, 370, 349, 327, 342, 354, 361, 354, 377, 324])

q = np.quantile(x, 0.25)

print(q)

print(len(x[x&lt;=q]) / len(x))

print(len(x[x&gt;=q]) / len(x))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">374</span>, <span class="pl-c1">358</span>, <span class="pl-c1">341</span>, <span class="pl-c1">355</span>, <span class="pl-c1">342</span>, <span class="pl-c1">334</span>, <span class="pl-c1">353</span>, <span class="pl-c1">346</span>, <span class="pl-c1">355</span>, <span class="pl-c1">344</span>,
              <span class="pl-c1">349</span>, <span class="pl-c1">330</span>, <span class="pl-c1">352</span>, <span class="pl-c1">328</span>, <span class="pl-c1">336</span>, <span class="pl-c1">359</span>, <span class="pl-c1">361</span>, <span class="pl-c1">345</span>, <span class="pl-c1">324</span>, <span class="pl-c1">386</span>,
              <span class="pl-c1">334</span>, <span class="pl-c1">370</span>, <span class="pl-c1">349</span>, <span class="pl-c1">327</span>, <span class="pl-c1">342</span>, <span class="pl-c1">354</span>, <span class="pl-c1">361</span>, <span class="pl-c1">354</span>, <span class="pl-c1">377</span>, <span class="pl-c1">324</span>])

<span class="pl-s1">q</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">quantile</span>(<span class="pl-s1">x</span>, <span class="pl-c1">0.25</span>)

<span class="pl-en">print</span>(<span class="pl-s1">q</span>)

<span class="pl-en">print</span>(<span class="pl-en">len</span>(<span class="pl-s1">x</span>[<span class="pl-s1">x</span><span class="pl-c1">&lt;=</span><span class="pl-s1">q</span>]) <span class="pl-c1">/</span> <span class="pl-en">len</span>(<span class="pl-s1">x</span>))

<span class="pl-en">print</span>(<span class="pl-en">len</span>(<span class="pl-s1">x</span>[<span class="pl-s1">x</span><span class="pl-c1">&gt;=</span><span class="pl-s1">q</span>]) <span class="pl-c1">/</span> <span class="pl-en">len</span>(<span class="pl-s1">x</span>))</pre></div>

<h3 dir="auto">Numpy/Python version information:</h3>

<p dir="auto">337.25</p>
<p dir="auto">0.26666666666666666</p>
<p dir="auto">0.7333333333333333</p>