[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NxN random matrix much cheaper than N^2 random scalars
From: |
Daniel Molina García |
Subject: |
NxN random matrix much cheaper than N^2 random scalars |
Date: |
Mon, 17 Nov 2014 16:55:51 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
Hello,
I am using GNU Octave, version 3.8.1. I found that generating a matrix,
for example as
for i=1:1
normrnd(0, 1, [n, 1]);
endfor
is much fast than
for i=1:n
normrnd(0, 1);
endfor
Why? Does it happen also in Matlab? It is motivating me to save the
exact huge amount of random numbers that I need in a very big array
before iterating, even considering the associated cost of memory.
Thanks,
Daniel
By the way, I found that specifying the 2 dimensions with a vector (as
in the above example) instead of using two parameters is quicker.
- NxN random matrix much cheaper than N^2 random scalars,
Daniel Molina García <=