Ask Your Question

# Revision history [back]

Unfortunately, matrices can only be defined over a ring, not a semiring. For example it is the same with nonnegative integers:

sage: matrix(NN, 2)
ValueError: Invalid matrix constructor.  Type matrix? for help


Unfortunately, matrices can only be defined over a ring, not a semiring. For example it is the same with nonnegative integers:

sage: matrix(NN, 2)
ValueError: Invalid matrix constructor.  Type matrix? for help


EDIT You can use numpy matrices for basic operations:

sage: import numpy as np
sage: M = np.matrix([[T(1),T(2)],[T(3),T(4)]])
sage: M
matrix([[1.00000000000000, 2.00000000000000],
[3.00000000000000, 4.00000000000000]], dtype=object)
sage: M*M
matrix([[2.00000000000000, 3.00000000000000],
[4.00000000000000, 5.00000000000000]], dtype=object)
sage: M+M
matrix([[1.00000000000000, 2.00000000000000],
[3.00000000000000, 4.00000000000000]], dtype=object)