You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
Hello All,
Please see the code below. Is this a bug in simpy?
from sympy import *
a = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = a
a.col_del(0)
print(a, b)
Expected answer: a = [ [2, 3]
[5, 6]
[8, 9]]
b = [ [1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
Actual answer: a = [ [2, 3]
[5, 6]
[8, 9]]
b = [ [2, 3]
[5, 6]
[8, 9]]
Thanks
Ash
Aaron Meurer
unread,
Sep 5, 2019, 1:14:09 PM9/5/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
The default Matrix class is mutable, which means that col_del modifies
a in-place. Since b points to the same matrix as a, it is also
modified in-place. See https://nedbatchelder.com/text/names.html.
It may be simpler to reason about an immutable matrix. Use
ImmutableMatrix instead of Matrix. In that case, a.col_del(0) will
return a new matrix and not modify a in-place.