[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shuffling elements in a dataset

From: Marvin Vis
Subject: Re: Shuffling elements in a dataset
Date: Fri, 21 Feb 97 16:13:31 MST

> I have the need to randomize the order (shuffle) of very large 
> datasets. The way I devise, randonly sampling with elimination, is 
> not very efficient. Is there a better way, using octave's matrix 
> manipulation? 
> Better way: perhaps creating a vector of unique indexes? but how to 
> do this? 
>     idx = 1:rows(data);
>     now shuffle idx
>     new_data = data(idx,:)
> Of course, this it is the same problem in one dimension...

I've done something along the lines of the following before:

        x = <data>  ....original data vector that you want to randomize

        n = rand(length(x),1);
        [garbage index] = sort(n);
        x_randomized = x(index);

You should be able to extend this to more dimensions as well....sort() is
relatively quick, so I've found this to be a decent approach.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]