# [Numpy-discussion] Find the N maximum values and correspondingindexes in an array

Thu Dec 3 00:34:34 CST 2009

```Is it relevant to scipy.stats.scoreatpercentile?
There is a comment is that function:

# TODO: this should be a simple wrapper around a well-written quantile
# function.  GNU R provides 9 quantile algorithms (!), with differing
# behaviour at, for example, discontinuities.

-----Original Message-----
From: numpy-discussion-bounces@scipy.org on behalf of Neal Becker
Sent: Thu 03-Dec-09 05:26
To: numpy-discussion@scipy.org
Subject: Re: [Numpy-discussion] Find the N maximum values and correspondingindexes in an array

Neal Becker wrote:

> Keith Goodman wrote:
> ...
>> Oh, I thought he meant there was a numpy function for partial
sorting.
>>
Try this one:

template<typename in_t>
inline void partial_sort (in_t in, int n_el) {
std::partial_sort (boost::begin (in), boost::begin(in) + n_el,
boost::end (in));
}
...
def ("partial_sort",
&partial_sort<pyublas::numpy_strided_vector<int32_t> >);
def ("partial_sort",
&partial_sort<pyublas::numpy_strided_vector<int64_t> >);
def ("partial_sort",
&partial_sort<pyublas::numpy_strided_vector<double> >);
---------
import pyublas
import numpy as np
u = np.arange (20)[::-1]
from numpy_fncs import partial_sort
partial_sort (u, 4)
In [2]: u
Out[2]:
array([ 0,  1,  2,  3, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,
7,
6,  5,  4])

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3850 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091203/288b4e14/attachment-0001.bin
```