# span of a matrixspace

given a matrix subspace of sparse matrices over a ring Q

M=MatrixSpace(Q,1000,1000, sparse=True)

I need a way to define the subspace N of M given a list of matrices of M

I tried to turn matrices into lists and use the VectorSpace category, however my matrices are sparse matrices, and this takes very long

def lista(A):  #converts a matrix into a list
return A.list()

def coor(P): # for the determined base B, it gives the coordinate vector of a matrix P
A=base(P)
k=len(P)
V=VectorSpace(Q,2**(2*k), sparse=True) #I would like to work with MatrixSpace instead
B=[] #this will be my basis
for i in range(len(A)):
a=A[i]
B.append(V(lista(a)))
W=W=V.span_of_basis(B) #I dont know if this function exists in MatrixSpace
p=W.coordinate_vector(V(lista(P)))
return p

edit retag close merge delete

1

Could you please provide the code of what you tried, so that we see where the problem is ?

Could you please provide the constructon of the list of matrices ?

Sort by » oldest newest most voted 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.

more