Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

`repr` applied on a matrix

Typically, the repr function returns a string that can be executed and yield the same value as the object. In sageMath, this is not the case for a matrix : repr has the same behaviour as the str function has and str applied to a matrix returns a "nice" representation of it:

M=matrix([[1, 1],[1, 1]])

print(repr(M)==str(M)) 
print(M)

printing

True
[1 1]
[1 1]

This is not the behaviour I was expecting. To compare with Numpy:

from numpy import array

M = array([[1, 1], [1, 1]])

print(repr(M))
print()
print(M)

outpouting

array([[1, 1],
       [1, 1]])

[[1 1]
 [1 1]]

Do I need to write my own repr function when applied to a matrix?