Ask Your Question

Revision history [back]

I am not sure to fully understand what you are looking for (as @dan_fulea pointed out, you should provide some simple example), but could it be the operator [:]? The later can be used either to initialize the components of a tensor field from a given list or to get all the components as a list. Here is some example:

sage: M = Manifold(2, 'M', structure='Riemannian')
sage: X.<x,y> = M.chart()
sage: g = M.metric()
sage: g[:] = [[1+x^2, x*y], [x*y, 1+y^2]]  # set components to the values in the r.h.s. list
sage: g.display()
g = (x^2 + 1) dx⊗dx + x*y dx⊗dy + x*y dy⊗dx + (y^2 + 1) dy⊗dy
sage: g[:]  # returns all components as a matrix
[x^2 + 1     x*y]
[    x*y y^2 + 1]
sage: list(g[:])  # returns all components as a list
[(x^2 + 1, x*y), (x*y, y^2 + 1)]