# Matrix multiplication of sparse matrix with matrix over polynomial ring

Hi all,

I would like to know how to multiply the following matrices I have constructed in Sage. Here is my code for a toy example:

from scipy.sparse import csr_matrix
row = [0,0,1]
col = [0,1,1]
data = [1,-1,1]
A = csr_matrix((data,(row,col)),shape=(4,4))

R.<x,y> = PolynomialRing(QQ,2)
B = matrix(R,2,2,[1,x,1,y])


When I try to multiply the matrices using A.dot(B), I end up with the error: "No supported conversion for types: (dtype('int64'), dtype('O'))"

Is there a way I can multiply these matrices and yield an output that is a csr_matrix? (I suspect I would want to convert the entries of my A matrix to be the same data type, but I am unaware of how to do this)

edit retag close merge delete

Sort by » oldest newest most voted

The scipy csr_format does not support custom datatypes such as Sage polynomials. You should use Sage matrices alone. If you want your matrix to be sparse, you can use

sage: row = [0,0,1]
sage: col = [0,1,1]
sage: data = [1,-1,1]
sage: data_for_sage = {(i,j):v for i,j,v in zip(row,col,data)}
sage: matrix(4, data_for_sage, sparse=True)
[ 1 -1  0]
[ 0  1  0]
[ 0  0  0]

more