comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Random selection of pairs
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Random selection of pairs [message #51244] Sun, 12 November 2006 04:55
Julio[1] is currently offline  Julio[1]
Messages: 52
Registered: May 2005
Member
Thanks guys... it will help.

Cheers,
Julio

Michael Galloy escreveu:

> Kenneth P. Bowman wrote:
>> It will be much simpler, and probably much quicker, to read all
>> of the pairs and then pick 100 randomly, like this script named
>> select_random:
>>
>> x = findgen(2, 1000) ;create fake lon-lat data
>> r = RANDOMU(seed, 1000) ;generate random numbers
>> j = (SORT(r))[0:9] ;find indices of 10 smallest numbers
>
> Yes, I think this is the way to do it.
>
> It won't help here with only 1000 elements, but I have a routine to get
> the indices of the n smallest (or largest) values in an array. It uses
> HISTOGRAM and REVERSE_INDICES instead of the SORT in the line
>
> j = (SORT(r))[0:9]
>
> The article describing it is at:
>
> http://michaelgalloy.com/2006/06/02/finding-the-n-smallest-e lements-in-an-array.html
>
>
> Mike
> --
> www.michaelgalloy.com
Re: Random selection of pairs [message #51246 is a reply to message #51244] Sat, 11 November 2006 20:30 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
Kenneth P. Bowman wrote:
> It will be much simpler, and probably much quicker, to read all
> of the pairs and then pick 100 randomly, like this script named
> select_random:
>
> x = findgen(2, 1000) ;create fake lon-lat data
> r = RANDOMU(seed, 1000) ;generate random numbers
> j = (SORT(r))[0:9] ;find indices of 10 smallest numbers

Yes, I think this is the way to do it.

It won't help here with only 1000 elements, but I have a routine to get
the indices of the n smallest (or largest) values in an array. It uses
HISTOGRAM and REVERSE_INDICES instead of the SORT in the line

j = (SORT(r))[0:9]

The article describing it is at:

http://michaelgalloy.com/2006/06/02/finding-the-n-smallest-e lements-in-an-array.html


Mike
--
www.michaelgalloy.com
Re: Random selection of pairs [message #51252 is a reply to message #51246] Sat, 11 November 2006 06:58 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <1163249745.126148.50070@h48g2000cwc.googlegroups.com>,
"Julio" <julio@cpa.unicamp.br> wrote:

> I have an array with two columns and a thousand of rows. Each row has a
> pair of latitude and longitude.
>
> Array=float(2, 1000)
>
> -27.3456 -54.6529
> -23.4546 -56.7263
> ... and so on...
>
> I need to retrieve only 100 pairs, randomly. How can I do that?
> Any comments welcome!
> Julio

It will be much simpler, and probably much quicker, to read all
of the pairs and then pick 100 randomly, like this script named
select_random:

x = findgen(2, 1000) ;create fake lon-lat data
r = RANDOMU(seed, 1000) ;generate random numbers
j = (SORT(r))[0:9] ;find indices of 10 smallest numbers
PRINT, j
PRINT, r[j]
FOR k = 0, 9 DO PRINT, x[*,j[k]] ;print 10 random pairs

IDL> @select_random
952 848 497 935 490 678 853 313
365 976
0.000964510 0.00113783 0.00255171 0.00340872 0.00390364 0.00452789 0.00609691
0.00676597 0.0117514 0.0121868
1904.00 1905.00
1696.00 1697.00
994.000 995.000
1870.00 1871.00
980.000 981.000
1356.00 1357.00
1706.00 1707.00
626.000 627.000
730.000 731.000
1952.00 1953.00

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Keystrokes While IN a Graphics Window?
Next Topic: colorbar positioning in postscript

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:10:05 PDT 2025

Total time taken to generate the page: 0.00578 seconds