Ask Your Question

Revision history [back]

The method change_ring is made for that:

sage: m = random_matrix(RDF, 3, 3)
sage: m
[  -0.5774223516523238    0.4648049987667806  -0.17171365230946778]
[-0.056437596814425284   -0.8482416820866097   -0.4433923816239411]
[  -0.8602958788377144   -0.6032286081857376    0.2704814323965121]
sage: m.change_ring(QQ)
[-122806609/212680733   66491472/143052403  -40134866/233731363]
[ -53603174/949777755  -91233993/107556602   -33210813/74901632]
[-538125967/625512664 -107008889/177393591   51117399/188986721]

Note that it does not change m:

sage: m
[  -0.5774223516523238    0.4648049987667806  -0.17171365230946778]
[-0.056437596814425284   -0.8482416820866097   -0.4433923816239411]
[  -0.8602958788377144   -0.6032286081857376    0.2704814323965121]