Skip to content

replace zeros in a block diagonal matrix with small random values?

2 messages · Rick DeShon, Dimitris Rizopoulos

#
Hi All.

Imagine you have a large block diagonal matrix.  I'd like to replace
the zeros in this matrix with small random (runif) numbers.  Any ideas
for a simple and efficient way to do this?

Best regards,

Rick DeShon
#
say 'mat' is your matrix, then you could try something like (untested):

ind <- mat == 0
mat[ind] <- runif(sum(ind))


I hope it helps.

Best,
Dimitris
Rick DeShon wrote: