我要 sample 无更换 m
1
之间的整数和 n
在 Matlab 中,其中
m=10^6;
p=13^5;
n=p*(p-1)/2;
我曾尝试使用 randsample
如下random_indices_pairs=randsample(n,m);
但是,我遇到了一个内存问题 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
有没有办法避免这种情况?这里的问题是由于 n
很大。
最佳答案
randperm
的两输入版本相当于 randsample
无需更换,并且没有内存问题:
random_indices_pairs = randperm(n, m);
关于matlab - 如何在不耗尽内存的情况下在 Matlab 中使用 randsample?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63175026/