Ask Your Question

Revision history [back]

It's better to set things up more conveniently from the beginning. Symbolically:

indices = [(i,j) for i in range(3) for j in range(5)]
variables = [var('y_{}_{}'.format(i,j)) for (i,j) in indices]
y = dict(zip(indices, variables))
M = matrix(SR, 3, 5, variables)

Or with polynomials:

indices = [(i,j) for i in range(3) for j in range(5)]
R = PolynomialRing(QQ, ['y_{}_{}'.format(i,j) for (i,j) in indices])
y = dict(zip(indices, R.gens()))
M = matrix(R, 3, 5, R.gens())

In both cases:

sage: y[2,0]
y_2_0
sage: M[1,3] is y[1,3]
True