Ask Your Question

Revision history [back]

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.

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())