Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to do it is to use apply_map:

sage: x = var('x')
sage: h = Matrix(SR, [[x,2],[3*x+5,4]])
sage: 
sage: h0 = h.apply_map(lambda i: i.coeff(x,0))
sage: h1 = h.apply_map(lambda i: i.coeff(x,1))
sage: h0
[0 2]
[5 4]
sage: h1
[1 0]
[3 0]

Or you could use one of the Matrix constructors:

sage: Matrix(2,2,lambda i,j: h[i,j].coeff(x,0))
[0 2]
[5 4]
sage: Matrix(2,2,lambda i,j: h[i,j].coeff(x,1))
[1 0]
[3 0]