Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One possible solution is to construct/return not only a matrix but also a mapping (dict) of variables to their indices - like:

def symbolic_matrix(root,m,n):
    var2ind = {}
    mlist=[]
    for i in range(m):
        for j in range(n):
            var2ind[SR(root+'_'+str(i)+'_'+str(j))] = [i,j]
            mlist.append(root+'_'+str(i)+'_'+str(j))
    return Matrix(SR,m,n,mlist), var2ind

k,n=4,8
r1, v2i = symbolic_matrix('y',k,n)

v2i[r1[2,3]]

One possible solution is to construct/return not only a matrix but also a mapping (dict) of variables to their indices - like:

def symbolic_matrix(root,m,n):
    var2ind = {}
    mlist=[]
    for i in range(m):
        for j in range(n):
            var2ind[SR(root+'_'+str(i)+'_'+str(j))] v = SR(root+'_'+str(i)+'_'+str(j))
            var2ind[v] = [i,j]
            mlist.append(root+'_'+str(i)+'_'+str(j))
mlist.append(v)
    return Matrix(SR,m,n,mlist), var2ind

k,n=4,8
r1, v2i = symbolic_matrix('y',k,n)

v2i[r1[2,3]]