Ask Your Question
0

Matrix multiplication of sparse matrix with matrix over polynomial ring

asked 2019-07-17 17:49:28 +0200

Bark gravatar image

updated 2023-05-19 22:04:59 +0200

FrédéricC gravatar image

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)

Thank you for your time!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2019-07-17 21:27:49 +0200

vdelecroix gravatar image

updated 2019-07-17 21:28:18 +0200

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-17 17:49:28 +0200

Seen: 404 times

Last updated: Jul 17 '19