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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<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 />

Mutable matrices are not hashable, so can’t be used as keys for dictionaries:<br />

sage: hash(A)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: mutable matrices are unhashable<br />

sage: v = {A:1}<br />

Traceback (most recent call last):<br />

...<br />

TypeError: mutable matrices are unhashable<br />

If we make A immutable it suddenly is hashable.<br />

sage: A.set_immutable()<br />

sage: A.is_mutable()<br />

False<br />

sage: A[0,0] = 10<br />

Traceback (most recent call last):<br />

...<br />

ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a<br />

sage: hash(A) #r<strong>and</strong>om<br />

12<br />

sage: v = {A:1}; v<br />

{[10 1]<br />

[ 2 3]: 1}<br />

set_row_to_multiple_<strong>of</strong>_row(i, j, s)<br />

Set row i equal to s times row j.<br />

EXAMPLES: We change the second row to -3 times the first row:<br />

sage: a = matrix(ZZ,2,3,range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: a.set_row_to_multiple_<strong>of</strong>_row(1,0,-3)<br />

sage: a<br />

[ 0 1 2]<br />

[ 0 -3 -6]<br />

If we try to multiply a row by a rational number, we get an error message:<br />

sage: a.set_row_to_multiple_<strong>of</strong>_row(1,0,1/2)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: Multiplying row by Rational Field element cannot be done over Integer Ring, use c<br />

str(rep_mapping=None, zero=None, plus_one=None, minus_one=None)<br />

Return a nice string representation <strong>of</strong> the matrix.<br />

INPUT:<br />

•rep_mapping - a dictionary or callable used to override the usual representation <strong>of</strong> elements.<br />

If rep_mapping is a dictionary then keys should be elements <strong>of</strong> the base ring <strong>and</strong> values the desired<br />

string representation. Values sent in via the other keyword arguments will override values in the<br />

dictionary. Use <strong>of</strong> a dictionary can potentially take a very long time due to the need to hash entries <strong>of</strong><br />

the matrix. <strong>Matrices</strong> with entries from QQbar are one example.<br />

If rep_mapping is callable then it will be called with elements <strong>of</strong> the matrix <strong>and</strong> must return a<br />

string. Simply call repr() on elements which should have the default representation.<br />

89

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

Saved successfully!

Ooh no, something went wrong!