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

Home » Public Forums » archive » Re: IDL function randperm?
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: IDL function randperm? [message #36154] Wed, 20 August 2003 21:00
meron is currently offline  meron
Messages: 51
Registered: July 1995
Member
In article <Amara.Graps-2008031259130001@amaramac.ifsi.rm.cnr.it>, Amara.Graps@ifsi.rm.cnr.it (Amara Graps) writes:
>
> Greetings!
>
> I wonder if any of you have an IDL function that gives a
> random permutation of an array index, or know of a
> straightforward way to compute it?
>
Look for SHUFFLE in my library, MIDL. You should find it on the RSI
user contributions page.

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: IDL function randperm? [message #36156 is a reply to message #36154] Wed, 20 August 2003 07:43 Go to previous message
robert.dimeo is currently offline  robert.dimeo
Messages: 42
Registered: November 2001
Member
Oops...mistake in the syntax of my last posting...

Try this:

function randperm,n
return,sort(randomn(s,n))
end


Amara.Graps@ifsi.rm.cnr.it (Amara Graps) wrote in message news:<Amara.Graps-2008031259130001@amaramac.ifsi.rm.cnr.it>...
> Greetings!
>
> I wonder if any of you have an IDL function that gives a
> random permutation of an array index, or know of a
> straightforward way to compute it?
>
> In Matlab such a function is called "randperm(n)"
> where n is the length of the array.
>
> For example, if one gives the integer 8, then it returns
> a length 8 integer array with values 0 to 7, randomly permutated.
>
> It is not as simple as it sounds, since the indices are unique.
> I tried variations of randomly SHIFT'g indices from INDGEN()
> with a random number generator, and the values were not
> 'jumbled' satisfactorily.
>
> Thanks in advance for any answer!
> Amara
Re: IDL function randperm? [message #36157 is a reply to message #36156] Wed, 20 August 2003 07:40 Go to previous message
robert.dimeo is currently offline  robert.dimeo
Messages: 42
Registered: November 2001
Member
Hi,

How about...

function randperm,n
return, array = sort(randomn(s,n))
end


Amara.Graps@ifsi.rm.cnr.it (Amara Graps) wrote in message news:<Amara.Graps-2008031259130001@amaramac.ifsi.rm.cnr.it>...
> Greetings!
>
> I wonder if any of you have an IDL function that gives a
> random permutation of an array index, or know of a
> straightforward way to compute it?
>
> In Matlab such a function is called "randperm(n)"
> where n is the length of the array.
>
> For example, if one gives the integer 8, then it returns
> a length 8 integer array with values 0 to 7, randomly permutated.
>
> It is not as simple as it sounds, since the indices are unique.
> I tried variations of randomly SHIFT'g indices from INDGEN()
> with a random number generator, and the values were not
> 'jumbled' satisfactorily.
>
> Thanks in advance for any answer!
> Amara
Re: IDL function randperm? [message #36158 is a reply to message #36157] Wed, 20 August 2003 06:52 Go to previous message
rigby is currently offline  rigby
Messages: 16
Registered: September 1995
Junior Member
This is what I use to randomly reorder an array, stripped down to its
essentials.I stole the idea from the old RSI newsletter many years
ago.

FUNCTION Randomize, list, seed
; LIST is the array to be randomized
; SEED is the random number generator seed

n = n_elements(list)
return, list[sort(randomu(seed,n))]

end ;; Randomize

IDL> seed = 1
IDL> print, Randomize( indgen(5), seed)
1 0 3 2 4

Note that randomu(), and thus Randomize(), returns SEED as a
36-element long array, tho' you can initialize it with a scalar.

--Wayne

Amara.Graps@ifsi.rm.cnr.it (Amara Graps) wrote in message news:<Amara.Graps-2008031259130001@amaramac.ifsi.rm.cnr.it>...

> I wonder if any of you have an IDL function that gives a
> random permutation of an array index, or know of a
> straightforward way to compute it?
Re: IDL function randperm? [message #36159 is a reply to message #36158] Wed, 20 August 2003 06:50 Go to previous message
Amara.Graps is currently offline  Amara.Graps
Messages: 11
Registered: November 1998
Junior Member
> If I understand your question, you can just generate n uniform random
> variables and then sort the result.
>> [...]
> Ken Bowman

Dear Ken,

Great! That's exactly what I wanted. Thanks alot.

Amara
--

************************************************************ *******
Amara Graps, PhD |Istituto di Fisica dello Spazio Interplanetario
| INAF, Roma, Italia
| tel +39-06-4993-4384 fax +39-06-4993-4383
http://www.mpi-hd.mpg.de/dustgroup/~graps
************************************************************ ******
"We came whirling out of Nothingness scattering stars like dust."
- Rumi
Re: IDL function randperm? [message #36160 is a reply to message #36159] Wed, 20 August 2003 06:00 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <Amara.Graps-2008031259130001@amaramac.ifsi.rm.cnr.it>,
Amara.Graps@ifsi.rm.cnr.it (Amara Graps) wrote:

> Greetings!
>
> I wonder if any of you have an IDL function that gives a
> random permutation of an array index, or know of a
> straightforward way to compute it?
>
> In Matlab such a function is called "randperm(n)"
> where n is the length of the array.
>
> For example, if one gives the integer 8, then it returns
> a length 8 integer array with values 0 to 7, randomly permutated.
>
> It is not as simple as it sounds, since the indices are unique.
> I tried variations of randomly SHIFT'g indices from INDGEN()
> with a random number generator, and the values were not
> 'jumbled' satisfactorily.
>
> Thanks in advance for any answer!
> Amara

If I understand your question, you can just generate n uniform random
variables and then sort the result.

IDL> x = LINDGEN(10)
IDL> y = RANDOMU(dseed, 10)
IDL> print, x
0 1 2 3 4 5
6 7
8 9
IDL> print, y
0.138249 0.0700486 0.310873 0.610514 0.332400
0.135694 0.975024
0.370555 0.763737 0.0268037
IDL> z = x[SORT(y)]
IDL> print, z
9 1 5 0 2 4
7 3
8 6


Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Two questions (about Mpeg and Networking)
Next Topic: bug in CONTOUR

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

Current Time: Wed Oct 08 13:48:58 PDT 2025

Total time taken to generate the page: 0.00886 seconds