[Top][All Lists]

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

Shuffling elements in a dataset

From: jcardoso
Subject: Shuffling elements in a dataset
Date: Fri, 21 Feb 97 22:02:24 GMT


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 

My way:

    nm = num = rows(data);

    for i=1:num
        rn = ceil(rand * nm--);
        new_data(i,:) = data(rn,:);
        data(rn,:) = [];

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...

Joao Cardoso, INESC  |  e-mail: address@hidden
R. Jose Falcao 110   |  tel:    + 351 2 2094345
4050 Porto, Portugal |  fax:    + 351 2 2008487

reply via email to

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