analysis/
mg_n_smallest.pro
Routines
top mg_n_smallest
result = mg_n_smallest(data, n [, /largest])
Finds the n
smallest elements of a data array. This algorithm works
fastest on uniformly distributed data. The worst case for it is a single
smallest data element and all other elements with another value. This will
be nearly equivalent to just sorting all the elements and choosing the first
n
elements.
Return value
index array
Parameters
- data in required type=numeric array
data array of any numeric type (except complex/dcomplex)
- n in required type=integer
number of smallest elements to find
Keywords
- largest in optional type=boolean
set to find
n
largest elements
Examples
For example, to find the 3 smallest values of 10 random values, try:
IDL> r = randomu(seed, 10)
IDL> print, r, format='(4F)'
0.6297589 0.7815896 0.2508559 0.7546844
0.1353382 0.1245834 0.8733745 0.0753110
0.8054136 0.9513228
IDL> ind = mg_n_smallest(r, 3)
IDL> print, r[ind]
0.0753110 0.124583 0.135338
File attributes
Modification date: | Wed May 14 15:07:14 2014 |
Lines: | 28 |
Docformat: | rst rst |
Contact me if you have enhancement requests or bug fixes.