Ask Your Question
0

Random matrix with density.

asked 2023-01-13 18:24:47 +0200

Cyrille gravatar image

I have a little question of comprehension

random_matrix(ZZ, 5, 4, x=0,y=11, density = 0.33)

generate a result like

[0 6 0 0]
[0 5 0 0]
[5 0 0 0]
[0 0 0 4]

but this gives 5 non zero enters which correspond, as I undeerstand it, to a density of 5/25 which is very far from .33 ? As always I suppose I have not clearly understood the meaning of density.

Should somebody explain this ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-01-13 20:15:11 +0200

updated 2023-01-13 21:49:35 +0200

According to the documentation,

The density keyword is used to compute the number of entries per row that will be nonzero, but the same entry may be selected more than once. So the value provided will be an upper bound for the density of the created matrix.

Since there are only 4 entries in each row, a density of 1/3 per row yields one nonzero entry per row.

If you want a matrix with specified global density, you could create a 1x20 matrix with the specified density and then convert it:

M_one_row = random_matrix(ZZ, 1, 20, x=0,y=11, density = 0.33)
M = matrix(5, 4, M_one_row.list())
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-01-13 18:24:47 +0200

Seen: 178 times

Last updated: Jan 13 '23