Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to take the index of a variable in sagemath?

I used the method in the post to generate a matrix with entries which have indices.

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

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

Now I would like to get the index of the entries of the matrix r1. For example, the index of y_1_2 is [1,2]. How to do this in sagemath? I tried something like y.index(y_1_2) but it doesn't work. Thank you very much.

How to take the index of a variable in sagemath?

I used the method in the post to generate a matrix with entries which have indices.

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

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

Now I would like to get the index of the entries of the matrix r1. For example, the index of y_1_2 is [1,2]. How to do this in sagemath? I tried something like y.index(y_1_2) but it doesn't work. Thank you very much.