1 | initial version |
You can use the apply_map
method which applies a function to each of the elements of the matrix. For example,
sage: m = matrix([[sin(x), cos(x)], [sin(x), cos(x)]]); m
[sin(x) cos(x)]
[sin(x) cos(x)]
sage: o = m*m.transpose(); o
[sin(x)^2 + cos(x)^2 sin(x)^2 + cos(x)^2]
[sin(x)^2 + cos(x)^2 sin(x)^2 + cos(x)^2]
sage: o.apply_map(lambda x: x.trig_reduce())
[1 1]
[1 1]
You could equivalently use attrcall
sage: o.apply_map(attrcall('trig_reduce'))
[1 1]
[1 1]