Ask Your Question

Revision history [back]

Let's create the space M:

sage: M = MatrixSpace(ZZ,2,2)
sage: M
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring

The default behavior is:

sage: M.random_element()
[-2  1]
[-3  0]

One may give an interval for the values:

sage: M.random_element(x=1000, y=2000)
[1308 1271]
[1451 1352]

One may increase the density of zero entries in the elements:

sage: M.random_element(x=1000, y=2000, density=.9)
[   0 1366]
[   0 1275]

One may provide a distribution, for instance the gaussian distribution with parameter sigma=x centered at zero. Below, I translate the center at 10^9:

sage: M.random_element(distribution='gaussian', x=10^9) + 10^9
[-203915342 -852236679]
[ 222400125 1463169355]

For further information and other possible inputs, read the below documentation :

sage: M.random_element?
sage: z = M.zero_matrix()
sage: z.randomize?
sage: ZZ.random_element?

Let's create the space M:

sage: M = MatrixSpace(ZZ,2,2)
sage: M
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring

The default behavior is:

sage: M.random_element()
[-2  1]
[-3  0]

One may give an interval for the values:

sage: M.random_element(x=1000, y=2000)
[1308 1271]
[1451 1352]

One may increase the density of zero entries in the elements:

sage: M.random_element(x=1000, y=2000, density=.9)
[   0 1366]
[   0 1275]

One may provide a distribution, for instance the gaussian distribution with parameter sigma=x centered at zero. Below, I translate the center at 10^9:

sage: M.random_element(distribution='gaussian', x=10^9) + 10^9
10^9 * M((1,1,1,1))
[-203915342 -852236679]
[ 222400125 1463169355]

For further information and other possible inputs, read the below documentation :

sage: M.random_element?
sage: z = M.zero_matrix()
sage: z.randomize?
sage: ZZ.random_element?