1 | initial version |
This will clean things up if the entries are integers. If the entries differ by small amounts from known algebraic numbers, that's more complicated.
sage: mat = matrix(3, 3, [2+1e-15+i*1e-15]*9)
sage: mat
[2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I]
[2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I]
[2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I 2.00000000000000 + 1.00000000000000e-15*I]
sage: mat.apply_map(lambda x: x.real().round())
[2 2 2]
[2 2 2]
[2 2 2]
sage: mat_Z = mat.apply_map(lambda x: x.real().round())
sage: mat_Z.base_ring()
Integer Ring