ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 27 Nov 2021 22:53:39 +0100Change the value of a single element in a matrixhttps://ask.sagemath.org/question/59982/change-the-value-of-a-single-element-in-a-matrix/Hi guys I wanna change the value of a singular element in a matrix in sagemath. How do I do this ? I get an error saying vector is immutable
A=matrix([[1,2,-3],[1,4,6],[2,-1,-2]])
B=matrix([[1],[2],[4]])
show(A)
show(B)
A[1][1]=6Sat, 27 Nov 2021 20:57:17 +0100https://ask.sagemath.org/question/59982/change-the-value-of-a-single-element-in-a-matrix/Answer by tmonteil for <p>Hi guys I wanna change the value of a singular element in a matrix in sagemath. How do I do this ? I get an error saying vector is immutable </p>
<pre><code>A=matrix([[1,2,-3],[1,4,6],[2,-1,-2]])
B=matrix([[1],[2],[4]])
show(A)
show(B)
A[1][1]=6
</code></pre>
https://ask.sagemath.org/question/59982/change-the-value-of-a-single-element-in-a-matrix/?answer=59985#post-id-59985See
sage: A[1]
(1, 4, 6)
sage: A[1].is_immutable()
True
You get a vector that is immutable. When you do
sage: A[1][1] = 6
you try to change the entry of index 1 of that vector, not the matrix `A`. The matrix `A` is mutable:
sage: A.is_mutable()
True
To change the entry of index `1,1` of the matrix `A`, you should do:
sage: A[1,1] = 6
So that
sage: A
[ 1 2 -3]
[ 1 6 6]
[ 2 -1 -2]Sat, 27 Nov 2021 22:53:39 +0100https://ask.sagemath.org/question/59982/change-the-value-of-a-single-element-in-a-matrix/?answer=59985#post-id-59985