jeudi 30 juillet 2020

How can I use randsample in Matlab without running out of memory?

I want to sample without replacement m integers between 1 and n in Matlab, where

m=10^6;
p=13^5;
n=p*(p-1)/2;

I have tried to use randsample as follows

random_indices_pairs=randsample(n,m);

However, I get a memory issue which is

    Error using zeros
    Requested 1x68929060278 (513.6GB) array exceeds maximum array size preference. Creation of arrays greater than this
    limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more
    information.

Error in randsample (line 149)
                x = zeros(1,n); % flags

Is there a way to avoid that? The issue here is due to the fact that n is huge.




Aucun commentaire:

Enregistrer un commentaire