Module: sage.matrix.matrix_generic_sparse
Sparse Matrices over a general ring
sage: R.<x> = PolynomialRing(QQ)
sage: M = MatrixSpace(QQ['x'],2,3,sparse=True); M
Full MatrixSpace of 2 by 3 sparse matrices over Univariate Polynomial Ring
in x over Rational Field
sage: a = M(range(6)); a
[0 1 2]
[3 4 5]
sage: b = M([x^n for n in range(6)]); b
[ 1 x x^2]
[x^3 x^4 x^5]
sage: a * b.transpose()
[ 2*x^2 + x 2*x^5 + x^4]
[ 5*x^2 + 4*x + 3 5*x^5 + 4*x^4 + 3*x^3]
sage: pari(a)*pari(b.transpose())
[2*x^2 + x, 2*x^5 + x^4; 5*x^2 + 4*x + 3, 5*x^5 + 4*x^4 + 3*x^3]
sage: c = copy(b); c
[ 1 x x^2]
[x^3 x^4 x^5]
sage: c[0,0] = 5; c
[ 5 x x^2]
[x^3 x^4 x^5]
sage: b[0,0]
1
sage: c.dict()
{(0, 1): x, (1, 2): x^5, (0, 0): 5, (1, 0): x^3, (0, 2): x^2, (1, 1): x^4}
sage: c.list()
[5, x, x^2, x^3, x^4, x^5]
sage: c.rows()
[(5, x, x^2), (x^3, x^4, x^5)]
sage: loads(dumps(c)) == c
True
sage: d = c.change_ring(CC['x']); d
[ 5.00000000000000 1.00000000000000*x 1.00000000000000*x^2]
[1.00000000000000*x^3 1.00000000000000*x^4 1.00000000000000*x^5]
sage: latex(c)
\left(\begin{array}{rrr}
5 \& x \& x^{2} \\
x^{3} \& x^{4} \& x^{5}
\end{array}\right)
sage: c.sparse_rows()
[(5, x, x^2), (x^3, x^4, x^5)]
sage: d = c.dense_matrix(); d
[ 5 x x^2]
[x^3 x^4 x^5]
sage: parent(d)
Full MatrixSpace of 2 by 3 dense matrices over Univariate Polynomial Ring
in x over Rational Field
sage: c.sparse_matrix() is c
True
sage: c.is_sparse()
True
Module-level Functions
| ) |
Input:
sage: V = VectorSpace(QQ,20,sparse=True) sage: v = V(0) sage: v[9] = 4 sage: from sage.matrix.matrix_generic_sparse import Matrix_sparse_from_rows sage: Matrix_sparse_from_rows([v]) [0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0] sage: Matrix_sparse_from_rows([v, v, v, V(0)]) [0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Class: Matrix_generic_sparse
The values of the dictionary must never be zero.
Special Functions: __copy__,
__eq__,
__ge__,
__gt__,
__init__,
__le__,
__lt__,
__ne__,
_dict,
_list,
_nonzero_positions_by_column,
_nonzero_positions_by_row,
_pickle,
_unpickle
| ) |
| ) |
Return the underlying dictionary of self.
| ) |
Return all entries of self as a list of numbers of rows times number of columns entries.
| ) |
| ) |
| ) |
| ) |
sage: a = matrix([[1,10],[3,4]],sparse=True); a [ 1 10] [ 3 4] sage: loads(dumps(a)) == a True
See About this document... for information on suggesting changes.