# Concatenate two sparse matrices over a Polynomial Ring

Hi all,

I am wondering if there is a way to concatenate two sparse matrices over a polynomial ring. Here is a toy example that I am testing with:

S.<x,y> = PolynomialRing(QQ,2)

udict = {(0,0):1, (0,1):x, (1,1):y}
vdict = {(0,0):2*x,(1,0):y}

U = matrix(4,4,ud,sparse=True)
V = matrix(4,2,vd,sparse=True)


I would like to make a larger matrix that is $4 \times 6$, that has the block form $[U|V]$. I attempted to use the block_matrix command, but it said that the given number of rows and columns were incompatible with the number of submatrices.

In Python, for a sparse matrix (csr_matrix or coo_matrix), there is the command hstack from scipy.sparse. Is there a similar command where I can concatenate a list of these sparse matrices? This would be ideal for my general problem.

edit retag close merge delete

Sort by » oldest newest most voted Like that

sage: U.augment(V)
[  1   x   0   0 2*x   0]
[  0   y   0   0   y   0]
[  0   0   0   0   0   0]
[  0   0   0   0   0   0]

more