Ask Your Question

Revision history [back]

Instead of converting sparse matrices to lists, try converting them to dictionaries.

M = MatrixSpace(QQ,10,10, sparse=True)
L = [M.random_element() for i in range(10)]  # my starting list of matrices
W = VectorSpace(QQ, 100, sparse=True)

LL = [] # will be new list of sparse vectors
for m in L:
    newdict = {}
    mdict = m.dict()
    for (i,j) in mdict:
        # convert matrix dictionary indexed by (i,j) to vector dictionary indexed by 10*i+j
        newdict[10*i+j] = mdict[i,j] 
    LL.append(W(newdict))

W.subspace(LL) # vector subspace of WW

In a perfect world, the following would work:

M = MatrixSpace(QQ,10,10, sparse=True)
L = [M.random_element() for i in range(10)]  # my starting list of matrices
M.submodule(L)

but when I try it, it raises an error.