Ask Your Question
2

Change the value of a single element in a matrix

asked 2021-11-27 20:57:17 +0100

aurelius_nero gravatar image

updated 2021-11-29 15:11:06 +0100

tmonteil gravatar image

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]=6
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2021-11-27 22:53:39 +0100

tmonteil gravatar image

updated 2021-11-27 22:55:42 +0100

See

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-11-27 20:57:17 +0100

Seen: 40 times

Last updated: Nov 29 '21