7.1.2.10 Matrix_generic_sparse Objects

class Matrix_generic_sparse
The Matrix_generic_sparse class derives from Matrix, and defines functionality for dense matrices over any base ring. A generic sparse matrix is represented using a dictionary with keys pairs $ (i,j)$ and values in the base ring.
Matrix_generic_sparse( parent, [entries=True], [coerce_entries=True], [copy=0])

Instances of class Matrix_generic_sparse have the following methods (in addition to inherited methods and special methods):

denominator,$  $ dict,$  $ entries,$  $ get,$  $ hessenberg_form,$  $ nonzero_positions,$  $ set,$  $ sparse_columns,$  $ sparse_rows,$  $ submatrix_from_columns,$  $ submatrix_from_rows,$  $ swap_rows,$  $ transpose

Further documentation:

get( ij)

Like __getitem__ but with no type or bounds checking. For (i,j) access, returns 0 if access is out of bounds.

hessenberg_form( )

Return the Hessenberg form of this matrix.

nonzero_positions( )

Returns the set of pairs (i,j) such that self[i,j] != 0.

set( ij, x)

Like __setitem__ but with no type or bounds checking. Only works for single entries, not whole rows.

submatrix_from_columns( columns)

Return the submatrix of self of columns col[i] for i in the list of columns.

submatrix_from_rows( rows)

Return the submatrix of self of rows row[i] for i in the list of rows.

swap_rows( r1, r2)

Swap rows r1 and r2 of self.

transpose( )

Returns the transpose of self, without changing self.

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

sage: M = MatrixSpace(RationalField(), 2, sparse=True)
sage: A = M([1,2,3,4])
sage: B = A.transpose()
sage: print B
[1 3]
[2 4]
sage: print A
[1 2]
[3 4]

Instances of class Matrix_generic_sparse also have the following special methods:

__getitem__,$  $ __mul__,$  $ __rmul__,$  $ __setitem__

Further documentation:

__getitem__( ij)

INPUT:
    A[i, j] -- the i,j of A, and
    A[i]    -- the i-th row of A.

__setitem__( ij, value)

INPUT:
    A[i, j] = value -- set the (i,j) entry of A
    A[i] = value    -- set the ith row of A

See About this document... for information on suggesting changes.