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.
If you are willing to work with a polynomial ring instead of the symbolic ring, then you can construct those with generators given as an array:
PolynomialRing(QQ, 3, 5, var_array='y')
. There is no obvious way to access the indices of those generators, unfortunately.