Dense matrices over the rational field.

EXAMPLES:

We create a 3x3 matrix with rational entries and do some operations with it.

sage: a = matrix(QQ, 3,3, [1,2/3, -4/5, 1,1,1, 8,2, -3/19]); a
[    1   2/3  -4/5]
[    1     1     1]
[    8     2 -3/19]
sage: a.det()
2303/285
sage: a.charpoly()
x^3 - 35/19*x^2 + 1259/285*x - 2303/285
sage: b = a^(-1); b
[ -615/2303  -426/2303   418/2303]
[ 2325/2303  1779/2303  -513/2303]
[-1710/2303   950/2303    95/2303]
sage: b.det()
285/2303
sage: a == b
False
sage: a < b
False
sage: b < a
True
sage: a > b
True
sage: a*b
[1 0 0]
[0 1 0]
[0 0 1]

TESTS:

sage: a = matrix(QQ,2,range(4), sparse=False)
sage: loads(dumps(a)) == a
True
class sage.matrix.matrix_rational_dense.MatrixWindow
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.matrix.matrix_rational_dense.Matrix_rational_dense
__copy__()

Copy a matrix over QQ.

EXAMPLES:

sage: a = MatrixSpace(QQ,3)([1/n for n in range(1,10)])
sage: -a
[  -1 -1/2 -1/3]
[-1/4 -1/5 -1/6]
[-1/7 -1/8 -1/9]
__eq__()
x.__eq__(y) <==> x==y
__ge__()
x.__ge__(y) <==> x>=y
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__invert__()

EXAMPLES:

sage: a = matrix(QQ,3,range(9))
sage: a.inverse()
...
ZeroDivisionError: input matrix must be nonsingular
sage: a = matrix(QQ, 2, [1, 5, 17, 3])
sage: a.inverse() 
[-3/82  5/82]
[17/82 -1/82]
__invert__main()

INPUT:

  • check_invertible - default: True (whether to check that matrix is invertible)

  • algorithm

    • default: “default” – use special cased code or pari up to 25 rows, then use iml
    • “pari” – use pari
    • “iml” – use an iml-based algorithm

OUTPUT: the inverse of self

Note

  • The n x n cases for n <= 2 are handcoded for speed.
  • The inverse function calls __invert__ which calls this.

EXAMPLES:

sage: a = matrix(QQ,3,[1,2,5,3,2,1,1,1,1,])
sage: a.__invert__main(check_invertible=False)
[1/2 3/2  -4]
[ -1  -2   7]
[1/2 1/2  -2]

A 1x1 matrix (a special case):

sage: a = matrix(QQ, 1, [390284089234])
sage: a.__invert__main()
[1/390284089234]

A 2x2 matrix (a special hand-coded case):

sage: a = matrix(QQ, 2, [1, 5, 17, 3]); a
[ 1  5]
[17  3]
sage: a.inverse() 
[-3/82  5/82]
[17/82 -1/82]
sage: a.__invert__main()  * a
[1 0]
[0 1]
__le__()
x.__le__(y) <==> x<=y
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
__neg__()

Negate a matrix over QQ.

EXAMPLES:

sage: a = MatrixSpace(QQ,3)([1/n for n in range(1,10)])
sage: -a
[  -1 -1/2 -1/3]
[-1/4 -1/5 -1/6]
[-1/7 -1/8 -1/9]
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_add_()

Add two dense matrices over QQ.

EXAMPLES:

sage: a = MatrixSpace(QQ,3)(range(9))
sage: b = MatrixSpace(QQ,3)([1/n for n in range(1,10)])
sage: a+b
[   1  3/2  7/3]
[13/4 21/5 31/6]
[43/7 57/8 73/9]
sage: b.swap_rows(1,2)
sage: #a+b
_add_col_j_of_A_to_col_i_of_self()

Unsafe technical function that very quickly adds the j-th column of A to the i-th column of self.

Does not check mutability.

_adjoint()

Return the adjoint of this matrix.

Assumes self is a square matrix (checked in adjoint).

EXAMPLES:

sage: m = matrix(QQ,3,[1..9])/9; m
[1/9 2/9 1/3]
[4/9 5/9 2/3]
[7/9 8/9   1]
sage: m.adjoint()
[-1/27  2/27 -1/27]
[ 2/27 -4/27  2/27]
[-1/27  2/27 -1/27]
_clear_denom()

INPUT:

  • self - a matrix

OUTPUT: D*self, D

The product is a matrix over ZZ

EXAMPLES:

sage: a = matrix(QQ,2,[-1/6,-7,3,5/4]); a
[-1/6   -7]
[   3  5/4]
sage: a._clear_denom()
([ -2 -84]
[ 36  15], 12)
_decomposition_rational()

Returns the decomposition of the free module on which this matrix A acts from the right (i.e., the action is x goes to x A), along with whether this matrix acts irreducibly on each factor. The factors are guaranteed to be sorted in the same way as the corresponding factors of the characteristic polynomial.

INPUT:

  • self - a square matrix over the rational numbers
  • echelon_algorithm - ‘default’
  • 'multimodular' - use this if the answers have small height
  • **kwds - passed on to echelon function.

Note

IMPORTANT: If you expect that the subspaces in the answer are spanned by vectors with small height coordinates, use algorithm=’multimodular’ and height_guess=1; this is potentially much faster than the default. If you know for a fact the answer will be very small, use algorithm=’multimodular’, height_guess=bound on height, proof=False

OUTPUT:

  • Sequence - list of tuples (V,t), where V is a vector spaces and t is True if and only if the charpoly of self on V is irreducible. The tuples are in order corresponding to the elements of the sorted list self.charpoly().factor().
_det_pari()

Return the determinant of this matrix computed using pari.

EXAMPLES::
sage: matrix(QQ,3,[1..9])._det_pari() 0 sage: matrix(QQ,3,[1..9])._det_pari(1) 0 sage: matrix(QQ,3,[0]+[2..9])._det_pari() 3
_echelon_form_multimodular()

Returns reduced row-echelon form using a multi-modular algorithm. Does not change self.

REFERENCE:

  • Chapter 7 of Stein’s “Explicitly Computing Modular Forms”.

INPUT:

  • height_guess - integer or None
  • proof - boolean (default: None, see proof.linear_algebra or sage.structure.proof) Note that the Sage global default is proof=True.
_echelon_form_padic()
Compute and return the echelon form of self using a p-adic nullspace algorithm.
_echelon_in_place_classical()

Compute the echelon form of self using classical algorithm and set the pivots of self. This is useful when the input matrix is small, or for timing or educational purposes.

EXAMPLES:

sage: a = matrix(QQ,2,[1..6])
sage: P = a._echelon_in_place_classical(); a
[ 1  0 -1]
[ 0  1  2]
_echelonize_multimodular()
_echelonize_padic()
Echelonize self using a p-adic nullspace algorithm.
_export_as_string()

Return space separated string of the entries in this matrix, in the given base. This is optimized for speed.

INPUT: base -an integer = 36; (default: 10)

EXAMPLES:

sage: m = matrix(QQ,2,3,[1,2/3,-3/4,1,-2/3,-45/17])
sage: m._export_as_string(10)
'1 2/3 -3/4 1 -2/3 -45/17'
sage: m._export_as_string(16)
'1 2/3 -3/4 1 -2/3 -2d/11'
_invert_pari()

Return the inverse of this matrix computed using pari.

EXAMPLES:

sage: matrix(QQ,2,[1,2,3,4])._invert_pari()
[  -2    1]
[ 3/2 -1/2]
_lift_crt_rr()
_lift_crt_rr_with_lcm()

Optimizations: When doing the rational_recon lift of a (mod m) first see if |a| < sqrt(m/2) in which case it lifts to an integer (often a=0 or 1).

If that fails, keep track of the lcm d of denominators found so far, and check to see if z = a*d lifts to an integer with |z| <= sqrt(m/2). If so, no need to do rational recon. This should be the case for most a after a while, and should saves substantial time!

_lmul_()

EXAMPLES:

sage: a = matrix(QQ,2,range(6))
sage: (3/4) * a
[   0  3/4  3/2]
[ 9/4    3 15/4]
_magma_init_()

EXAMPLES:

sage: m = matrix(QQ,2,3,[1,2/3,-3/4,1,-2/3,-45/17])
sage: m._magma_init_(magma)
'Matrix(RationalField(),2,3,StringToIntegerSequence("204 136 -153 204 -136 -540"))/204'
sage: magma(m)                                                # optional - magma
[     1    2/3   -3/4]
[     1   -2/3 -45/17]
_multiply_classical()

Use the standard O(n^3) matrix multiplication algorithm. This is never used by default, since it is slow.

EXAMPLES:

sage: n = 3
sage: a = matrix(QQ,n,range(n^2))/3
sage: b = matrix(QQ,n,range(1, n^2 + 1))/5
sage: a._multiply_classical(b)
[ 6/5  7/5  8/5]
[18/5 22/5 26/5]
[   6 37/5 44/5]
_multiply_over_integers()

Multiply this matrix by right using a multimodular algorithm and return the result.

INPUT:

  • self - matrix over QQ
  • right - matrix over QQ
  • algorithm
    • ‘default’: use whatever is the default for A*B when A, B are over ZZ.
    • ‘multimodular’: use a multimodular algorithm

EXAMPLES:

sage: a = MatrixSpace(QQ,10,5)(range(50))
sage: b = MatrixSpace(QQ,5,12)([1/n for n in range(1,61)])
sage: a._multiply_over_integers(b) == a._multiply_over_integers(b, algorithm='multimodular')
True
sage: a = MatrixSpace(QQ,3)(range(9))
sage: b = MatrixSpace(QQ,3)([1/n for n in range(1,10)])
sage: a._multiply_over_integers(b, algorithm = 'multimodular')
[ 15/28   9/20   7/18]
[  33/7 117/40   20/9]
[249/28   27/5  73/18]
_multiply_pari()

Return the product of self and right, computed using PARI.

EXAMPLES:

sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9])._multiply_pari(matrix(QQ,2,[1,2,3,4]))
[  -9/5 -34/15]
[ 25/12  59/18]

We verify that 0 rows or columns works:

sage: x = matrix(QQ,2,0); y= matrix(QQ,0,2); x*y
[0 0]
[0 0]  
_pari_()

Return pari version of this matrix.

EXAMPLES:

sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9])._pari_()
[1/5, -2/3; 3/4, 4/9]
_pickle()
_rank_pari()

Return the rank of this matrix computed using pari.

EXAMPLES:

sage: matrix(QQ,3,[1..9])._rank_pari()
2
_set_row_to_negative_of_row_of_A_using_subset_of_columns()

Set row i of self to -(row r of A), but where we only take the given column positions in that row of A. We do not zero out the other entries of self’s row i either.

INPUT:

  • i - integer, index into the rows of self
  • A - a matrix
  • r - integer, index into rows of A
  • cols - a sorted list of integers.

EXAMPLES:

sage: a = matrix(QQ,2,3,range(6)); a
[0 1 2]
[3 4 5]
sage: a._set_row_to_negative_of_row_of_A_using_subset_of_columns(0,a,1,[1,2])
sage: a
[-4 -5  2]
[ 3  4  5]
_sub_()

Subtract two dense matrices over QQ.

EXAMPLES:

sage: a = MatrixSpace(QQ,3)(range(9))
sage: b = MatrixSpace(QQ,3)([1/n for n in range(1,10)])
sage: a-b
[  -1  1/2  5/3]
[11/4 19/5 29/6]
[41/7 55/8 71/9]
_unpickle()
antitranspose()

Returns the antitranspose of self, without changing self.

EXAMPLES:

sage: A = matrix(QQ,2,3,range(6))
sage: type(A)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>
sage: A.antitranspose()
[5 2]
[4 1]
[3 0]
sage: A
[0 1 2]
[3 4 5]

sage: A.subdivide(1,2); A
[0 1|2]
[---+-]
[3 4|5]
sage: A.antitranspose()
[5|2]
[-+-]
[4|1]
[3|0]
change_ring()

Create the matrix over R with entries the entries of self coerced into R.

EXAMPLES:

sage: a = matrix(QQ,2,[1/2,-1,2,3])
sage: a.change_ring(GF(3))
[2 2]
[2 0]
sage: a.change_ring(ZZ)
...
TypeError: matrix has denominators so can't change to ZZ.
sage: b = a.change_ring(QQ['x']); b
[1/2  -1]
[  2   3]
sage: b.parent()
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field

TESTS:

Make sure that subdivisions are preserved when changing rings:

sage: a = matrix(QQ, 3, range(9))
sage: a.subdivide(2,1); a
[0|1 2]
[3|4 5]
[-+---]
[6|7 8]
sage: a.change_ring(ZZ).change_ring(QQ)
[0|1 2]
[3|4 5]
[-+---]
[6|7 8]
sage: a.change_ring(GF(3))
[0|1 2]
[0|1 2]
[-+---]
[0|1 2]
charpoly()

Return the characteristic polynomial of this matrix.

INPUT:

  • var - ‘x’ (string)
  • algorithm - ‘linbox’ (default) or ‘generic’

OUTPUT: a polynomial over the rational numbers.

EXAMPLES:

sage: a = matrix(QQ, 3, [4/3, 2/5, 1/5, 4, -3/2, 0, 0, -2/3, 3/4])
sage: f = a.charpoly(); f
x^3 - 7/12*x^2 - 149/40*x + 97/30
sage: f(a)
[0 0 0]
[0 0 0]
[0 0 0]
column()

Return the i-th column of this matrix as a dense vector.

INPUT:
  • i - integer
  • from_list - ignored

EXAMPLES:

sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).column(1)
(-2/3, 4/9)
sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).column(1,from_list=True)
(-2/3, 4/9)
sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).column(-1)
(-2/3, 4/9)
sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).column(-2)
(1/5, 3/4)
decomposition()

Returns the decomposition of the free module on which this matrix A acts from the right (i.e., the action is x goes to x A), along with whether this matrix acts irreducibly on each factor. The factors are guaranteed to be sorted in the same way as the corresponding factors of the characteristic polynomial.

Let A be the matrix acting from the on the vector space V of column vectors. Assume that A is square. This function computes maximal subspaces W_1, ..., W_n corresponding to Galois conjugacy classes of eigenvalues of A. More precisely, let f(X) be the characteristic polynomial of A. This function computes the subspace W_i = ker(g_(A)^n), where g_i(X) is an irreducible factor of f(X) and g_i(X) exactly divides f(X). If the optional parameter is_diagonalizable is True, then we let W_i = ker(g(A)), since then we know that ker(g(A)) = ker(g(A)^n).

If dual is True, also returns the corresponding decomposition of V under the action of the transpose of A. The factors are guaranteed to correspond.

INPUT:

  • is_diagonalizable - ignored
  • dual - whether to also return decompositions for the dual
  • algorithm
    • ‘default’: use default algorithm for computing Echelon forms
    • ‘multimodular’: much better if the answers factors have small height
  • height_guess - positive integer; only used by the multimodular algorithm
  • proof - bool or None (default: None, see proof.linear_algebra or sage.structure.proof); only used by the multimodular algorithm. Note that the Sage global default is proof=True.

Note

IMPORTANT: If you expect that the subspaces in the answer are spanned by vectors with small height coordinates, use algorithm=’multimodular’ and height_guess=1; this is potentially much faster than the default. If you know for a fact the answer will be very small, use algorithm=’multimodular’, height_guess=bound on height, proof=False.

You can get very very fast decomposition with proof=False.

EXAMPLES:

sage: a = matrix(QQ,3,[1..9])
sage: a.decomposition()
[
(Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -2  1], True),
(Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1  0 -1]
[ 0  1  2], True)
]
denominator()

Return the denominator of this matrix.

OUTPUT: a Sage Integer

EXAMPLES:

sage: b = matrix(QQ,2,range(6)); b[0,0]=-5007/293; b
[-5007/293         1         2]
[        3         4         5]
sage: b.denominator()
293
determinant()

Return the determinant of this matrix.

INPUT:

  • proof - bool or None; if None use proof.linear_algebra(); only relevant for the padic algorithm.

  • algorithm:

    “default” – use PARI for up to 7 rows, then use integer

    “pari” – use PARI

    “integer” – clear denominators and call det on integer matrix

Note

It would be VERY VERY hard for det to fail even with proof=False.

ALGORITHM: Clear denominators and call the integer determinant function.

EXAMPLES:

sage: m = matrix(QQ,3,[1,2/3,4/5, 2,2,2, 5,3,2/5])
sage: m.determinant()
-34/15
sage: m.charpoly()
x^3 - 17/5*x^2 - 122/15*x + 34/15
echelon_form()

INPUT:

  • algorithm
    • ‘default’ (default): use heuristic choice
    • ‘padic’: an algorithm based on the IML p-adic solver.
    • ‘multimodular’: uses a multimodular algorithm the uses linbox modulo many primes.
    • ‘classical’: just clear each column using Gauss elimination
  • height_guess, **kwds - all passed to the multimodular algorithm; ignored by the p-adic algorithm.
  • proof - bool or None (default: None, see proof.linear_algebra or sage.structure.proof). Passed to the multimodular algorithm. Note that the Sage global default is proof=True.

OUTPUT: self is no in reduced row echelon form.

EXAMPLES:

sage: a = matrix(QQ, 4, range(16)); a[0,0] = 1/19; a[0,1] = 1/5; a
[1/19  1/5    2    3]
[   4    5    6    7]
[   8    9   10   11]
[  12   13   14   15]
sage: a.echelon_form()
[      1       0       0 -76/157]
[      0       1       0  -5/157]
[      0       0       1 238/157]
[      0       0       0       0]
sage: a.echelon_form(algorithm='multimodular')
[      1       0       0 -76/157]
[      0       1       0  -5/157]
[      0       0       1 238/157]
[      0       0       0       0]
echelonize()

INPUT:

  • algorithm
  • ‘default’ (default): use heuristic choice
  • ‘padic’: an algorithm based on the IML p-adic solver.
  • ‘multimodular’: uses a multimodular algorithm the uses linbox modulo many primes.
  • ‘classical’: just clear each column using Gauss elimination
  • height_guess, **kwds - all passed to the multimodular algorithm; ignored by the p-adic algorithm.
  • proof - bool or None (default: None, see proof.linear_algebra or sage.structure.proof). Passed to the multimodular algorithm. Note that the Sage global default is proof=True.

OUTPUT:

  • matrix - the reduced row echelon for of self.

EXAMPLES:

sage: a = matrix(QQ, 4, range(16)); a[0,0] = 1/19; a[0,1] = 1/5; a
[1/19  1/5    2    3]
[   4    5    6    7]
[   8    9   10   11]
[  12   13   14   15]
sage: a.echelonize(); a
[      1       0       0 -76/157]
[      0       1       0  -5/157]
[      0       0       1 238/157]
[      0       0       0       0]
sage: a = matrix(QQ, 4, range(16)); a[0,0] = 1/19; a[0,1] = 1/5
sage: a.echelonize(algorithm='multimodular'); a
[      1       0       0 -76/157]
[      0       1       0  -5/157]
[      0       0       1 238/157]
[      0       0       0       0]
height()

Return the height of this matrix, which is the maximum of the absolute values of all numerators and denominators of entries in this matrix.

OUTPUT: an Integer

EXAMPLES:

sage: b = matrix(QQ,2,range(6)); b[0,0]=-5007/293; b
[-5007/293         1         2]
[        3         4         5]
sage: b.height()
5007
invert()

Compute the inverse of this matrix.

Warning

This function is deprecated. Use inverse instead.

EXAMPLES:

sage: a = matrix(QQ,3,range(9))
sage: a.invert()
...
ZeroDivisionError: input matrix must be nonsingular
minpoly()

Return the minimal polynomial of this matrix.

INPUT:

  • var - ‘x’ (string)
  • algorithm - ‘linbox’ (default) or ‘generic’

OUTPUT: a polynomial over the rational numbers.

EXAMPLES:

sage: a = matrix(QQ, 3, [4/3, 2/5, 1/5, 4, -3/2, 0, 0, -2/3, 3/4])
sage: f = a.minpoly(); f           
x^3 - 7/12*x^2 - 149/40*x + 97/30
sage: a = Mat(ZZ,4)(range(16))
sage: f = a.minpoly(); f.factor()  
x * (x^2 - 30*x - 80)
sage: f(a) == 0                    
True
sage: a = matrix(QQ, 4, [1..4^2])
sage: factor(a.minpoly())
x * (x^2 - 34*x - 80)
sage: factor(a.minpoly('y'))
y * (y^2 - 34*y - 80)
sage: factor(a.charpoly())
x^2 * (x^2 - 34*x - 80)
sage: b = matrix(QQ, 4, [-1, 2, 2, 0, 0, 4, 2, 2, 0, 0, -1, -2, 0, -4, 0, 4])
sage: a = matrix(QQ, 4, [1, 1, 0,0, 0,1,0,0, 0,0,5,0, 0,0,0,5])
sage: c = b^(-1)*a*b
sage: factor(c.minpoly())
(x - 5) * (x - 1)^2
sage: factor(c.charpoly())
(x - 5)^2 * (x - 1)^2
prod_of_row_sums()
randomize()

Randomize density proportion of the entries of this matrix, leaving the rest unchanged.

If x and y are given, randomized entries of this matrix have numerators and denominators bounded by x and y and have density 1.

INPUT:

  • density – number between 0 and 1 (default: 1)
  • num_bound – numerator bound (default: 2)
  • den_bound – denominator bound (default: 2)
  • distribution – None or ‘1/n’ (default: None); if ‘1/n’ then num_bound, den_bound are ignored and numbers are chosen using the GMP function mpq_randomize_entry_recip_uniform

EXAMPLES:

sage: a = matrix(QQ,2,4); a.randomize(); a
[ 0 -1  2 -2]
[ 1 -1  2  1]
sage: a = matrix(QQ,2,4); a.randomize(density=0.5); a
[ -1  -2   0   0]
[  0   0 1/2   0]
sage: a = matrix(QQ,2,4); a.randomize(num_bound=100, den_bound=100); a
[ 14/27  21/25  43/42 -48/67]
[-19/55  64/67 -11/51     76]
sage: a = matrix(QQ,2,4); a.randomize(distribution='1/n'); a
[      3     1/9     1/2     1/4]
[      1    1/39       2 -1955/2]
rank()

Return the rank of this matrix.

EXAMPLES::
sage: matrix(QQ,3,[1..9]).rank() 2 sage: matrix(QQ,100,[1..100^2]).rank() 2
right_kernel()

Return the right kernel of this matrix, as a vector space over QQ. For a left kernel use self.left_kernel() or just self.kernel().

INPUT:

  • algorithm - ‘padic’ (or ‘default’): use IML’s p-adic nullspace algorithm
  • anything else - passed on to the generic echelon-form based algorithm.
  • **kwds - passed onto to echelon form algorithm in the echelon case.

EXAMPLES:

A non-trivial right kernel over the rationals::

    sage: A = matrix(QQ, [[2,1,-5,-8],[-1,-1,4,6],[1,0,-1,-2]])
    sage: A.right_kernel()
    Vector space of degree 4 and dimension 2 over Rational Field
    Basis matrix:
    [   1    0   -2  3/2]
    [   0    1    1 -1/2]

A trivial right kernel, plus left kernel (via superclass)::

    sage: M=Matrix(QQ,[[1/2,3],[0,1],[1,1]])
    sage: M.right_kernel()
    Vector space of degree 2 and dimension 0 over Rational Field
    Basis matrix:
    []
    sage: M.left_kernel()
    Vector space of degree 3 and dimension 1 over Rational Field
    Basis matrix:
    [   1 -5/2 -1/2]
row()

Return the i-th row of this matrix as a dense vector.

INPUT:
  • i - integer
  • from_list - ignored

EXAMPLES:

sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).row(1)
(3/4, 4/9)
sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).row(1,from_list=True)
(3/4, 4/9)
sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9]).row(-2)
(1/5, -2/3)
set_row_to_multiple_of_row()

Set row i equal to s times row j.

EXAMPLES:

sage: a = matrix(QQ,2,3,range(6)); a
[0 1 2]
[3 4 5]
sage: a.set_row_to_multiple_of_row(1,0,-3)
sage: a
[ 0  1  2]
[ 0 -3 -6]
transpose()

Returns the transpose of self, without changing self.

EXAMPLES:

We create a matrix, compute its transpose, and note that the original matrix is not changed.

sage: A = matrix(QQ,2,3,xrange(6))
sage: type(A)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>
sage: B = A.transpose()
sage: print B
[0 3]
[1 4]
[2 5]
sage: print A
[0 1 2]
[3 4 5]

sage: A.subdivide(None, 1); A
[0|1 2]
[3|4 5]
sage: A.transpose()
[0 3]
[---]
[1 4]
[2 5]
sage.matrix.matrix_rational_dense.clear_mpz_globals()
sage.matrix.matrix_rational_dense.gmp_randrange()
sage.matrix.matrix_rational_dense.init_mpz_globals()

Previous topic

Dense matrices over the integer ring.

Next topic

Dense matrices over the Real Double Field using NumPy

This Page