08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

Here we make a r<strong>and</strong>om matrix over RR <strong>and</strong> use cmap=’hsv’ to color the matrix elements different RGB<br />

colors (see documentation for matrix_plot for more information on cmaps):<br />

sage: A = r<strong>and</strong>om_matrix(RDF, 50)<br />

sage: plot(A, cmap=’hsv’)<br />

Another r<strong>and</strong>om plot, but over GF(389):<br />

sage: A = r<strong>and</strong>om_matrix(GF(389), 10)<br />

sage: A.plot(cmap=’Oranges’)<br />

prod_<strong>of</strong>_row_sums(cols)<br />

Calculate the product <strong>of</strong> all row sums <strong>of</strong> a submatrix <strong>of</strong> A for a list <strong>of</strong> selected columns cols.<br />

EXAMPLES:<br />

sage: a = matrix(QQ, 2,2, [1,2,3,2]); a<br />

[1 2]<br />

[3 2]<br />

sage: a.prod_<strong>of</strong>_row_sums([0,1])<br />

15<br />

Another example:<br />

sage: a = matrix(QQ, 2,3, [1,2,3,2,5,6]); a<br />

[1 2 3]<br />

[2 5 6]<br />

sage: a.prod_<strong>of</strong>_row_sums([1,2])<br />

55<br />

AUTHORS:<br />

•Jaap Spies (2006-02-18)<br />

r<strong>and</strong>omize(density=1, nonzero=False, *args, **kwds)<br />

R<strong>and</strong>omize density proportion <strong>of</strong> the entries <strong>of</strong> this matrix, leaving the rest unchanged.<br />

Note: We actually choose at r<strong>and</strong>om density proportion <strong>of</strong> entries <strong>of</strong> the matrix <strong>and</strong> set them to<br />

r<strong>and</strong>om elements. It’s possible that the same position can be chosen multiple times, especially for a very<br />

small matrix.<br />

INPUT:<br />

•density - float (default: 1); rough measure <strong>of</strong> the proportion <strong>of</strong> nonzero entries in the r<strong>and</strong>om<br />

matrix<br />

•nonzero - Bool (default: False); whether the new entries have to be non-zero<br />

•*args, **kwds - Remaining parameters may be passed to the r<strong>and</strong>om_element function <strong>of</strong><br />

the base ring<br />

EXAMPLES:<br />

We construct the zero matrix over a polynomial ring.<br />

sage: a = matrix(QQ[’x’], 3); a<br />

[0 0 0]<br />

[0 0 0]<br />

[0 0 0]<br />

We then r<strong>and</strong>omize roughly half the entries:<br />

223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!