Ask Your Question

# Revision history [back]

If you want to print only, say, 3 significative digits, you can do:

sage: B = random_matrix(RDF,5,5)
sage: B
[   0.23432333232  -0.227616100926  -0.599156411098    0.41166189832   0.764641434688]
[  0.439380654181  -0.320536940171   0.320947963409  -0.847122064875   0.404266447713]
[ -0.908186671809   0.622848454479   0.219215554761  -0.872284101116  -0.286278011806]
[  -0.68809928219   0.779797277388    0.12146772553   0.864262076944 -0.0156592746181]
[  0.807522456479  -0.294491803547  -0.569575247674  -0.850921782049  -0.521678331812]

sage: print B.str(rep_mapping=lambda x : str(x.n(digits=3)))
[  0.234  -0.228  -0.599   0.412   0.765]
[  0.439  -0.321   0.321  -0.847   0.404]
[ -0.908   0.623   0.219  -0.872  -0.286]
[ -0.688   0.780   0.121   0.864 -0.0157]
[  0.807  -0.294  -0.570  -0.851  -0.522]


If you want to print only, say, 3 significative significant digits, you can do:

sage: B = random_matrix(RDF,5,5)
sage: B
[   0.23432333232  -0.227616100926  -0.599156411098    0.41166189832   0.764641434688]
[  0.439380654181  -0.320536940171   0.320947963409  -0.847122064875   0.404266447713]
[ -0.908186671809   0.622848454479   0.219215554761  -0.872284101116  -0.286278011806]
[  -0.68809928219   0.779797277388    0.12146772553   0.864262076944 -0.0156592746181]
[  0.807522456479  -0.294491803547  -0.569575247674  -0.850921782049  -0.521678331812]

sage: print B.str(rep_mapping=lambda x : str(x.n(digits=3)))
[  0.234  -0.228  -0.599   0.412   0.765]
[  0.439  -0.321   0.321  -0.847   0.404]
[ -0.908   0.623   0.219  -0.872  -0.286]
[ -0.688   0.780   0.121   0.864 -0.0157]
[  0.807  -0.294  -0.570  -0.851  -0.522]