Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Look at the documentation A.__getitem__? for the explanation. In short, A[0] returns the first row of the matrix which is an immutable vector. And A[0][0] returns the first entry of that vector.

If you want the first entry of the matrix directly, then use A[0,0]. In this case, you don't need to work with a copy and you can change the original matrix directly since the matrices are not immutable by default.

sage: A = matrix(3,3,0); A   
[0 0 0]
[0 0 0]
[0 0 0]
sage: A.is_immutable()
False
sage: A[0,0] = 1; A
[1 0 0]
[0 0 0]
[0 0 0]
sage: A[0]
(1, 0, 0)
sage: A[0].is_immutable()
True