Re: Random Sampling Without Replacement [message #72872] |
Wed, 13 October 2010 09:01 |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 10/13/10 9:46 AM, David Fanning wrote:
> Has anyone coded up an IDL algorithm to do random
> sampling without replacement?
>
> For example, suppose I want to sample values in
> my 2D image. I want, say, 100 values that represent
> individual pixel locations in the image. How can
> I make sure I get 100 unique, but random, locations?
To randomly sample m elements from n elements, I have used this albeit
inefficient technique:
m = 3
n = 100
im = findgen(n) ; input array
arr = randomu(seed, n)
ind = sort(arr)
print, im[ind[0:m-1]] ; m random elements from im
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|
|
|