Dear all, I am finding difficulty in the following, I would like to
create an empty matrix e.g. 10x10 of 0s and sequentially fill this
matrix with randomly placed a 1s until it is saturated. Producing 100
matrices of sequentially increasing density., This process needs to be
randomized 1000
I have to admit I'm not entirely sure what your question is. How to
put a 1 in a random position in a matrix?
mat - matrix(0, 10, 10)
mat[sample(1:nrow(mat), 1), sample(1:ncol(mat), 1)] - 1
will do so, but if you need to fill a random position that is *currently zero*
then you'll need to wrap it
Folks:
On Tue, Nov 29, 2011 at 6:24 AM, Sarah Goslee sarah.gos...@gmail.com wrote:
I have to admit I'm not entirely sure what your question is. How to
put a 1 in a random position in a matrix?
mat - matrix(0, 10, 10)
mat[sample(1:nrow(mat), 1), sample(1:ncol(mat), 1)] - 1
This is
On Nov 29, 2011, at 7:32 AM, Grant McDonald wrote:
Dear all, I am finding difficulty in the following, I would like to
create an empty matrix e.g. 10x10 of 0s and sequentially fill this
matrix with randomly placed a 1s until it is saturated. Producing 100
matrices of sequentially increasing
Hi:
Here's one approach. I assume that your first 1000 matrices have a
single 1 in each matrix, the next set of 1000 have two 1's, ..., and
the last one has 99 1's. (No point in doing all 1's since they're all
constant.) If that's the case, then try the following.
# Each row represents a
5 matches
Mail list logo