1 | initial version |
As mentioned in the comments you can do a lift.
For vectors you can also change the ring to the integers, to lift all the entries. For example,
def ones_per_column(matrices):
return sum(vector(sum(c.change_ring(ZZ)) for c in m.columns()) for m in matrices)
Maybe more efficiently, change the ring of each matrix to the integers, add them and take the column sums:
def ones_per_column(matrices):
return vector(sum(c) for c in sum(m.change_ring(ZZ) for m in matrices).columns())
In either case you can do
sage: ones_per_column(list(MatrixSpace(GF(2), 2, 2))[0:4])
(2, 1)
2 | No.2 Revision |
As mentioned in the comments you can do a lift.
For vectors you can also change the ring to the integers, to lift all the entries. For example,
def ones_per_column(matrices):
return sum(vector(sum(c.change_ring(ZZ)) for c in m.columns()) for m in matrices)
Maybe more efficiently, change the ring of each matrix to the integers, add them and take the column sums:
def ones_per_column(matrices):
return vector(sum(c) for c in sum(m.change_ring(ZZ) for m in matrices).columns())
In either case you can do
sage: ones_per_column(list(MatrixSpace(GF(2), 2, 2))[0:4])
(2, 1)