Creating a new matrix with removing columns in anoter doesn't work

25 views
Skip to first unread message

mura...@erzurum.edu.tr

unread,
May 3, 2019, 3:50:29 AM5/3/19
to sympy
Hello,
  
    I am new to sympy and I want removed one column of a matrix and I want to keep the original one also but when I use col_del() command it deletes the column for all matrices. Do you have idea how I can keep original while I changing matrix with another name?
The example I am writing is like that

    q=sp.Matrix([[x,x+1],[x-1,x+2]])
    
    w=q
    
    w.col_del(0)
    w1=w

  Then all q, w, w1 have deleted columns but I want to keep q unchanged.

Kalevi Suominen

unread,
May 3, 2019, 4:01:36 AM5/3/19
to sympy
Perhaps you should make a copy of q:  w = q.copy().

Kalevi Suominen

Vishesh Mangla

unread,
May 3, 2019, 4:03:36 AM5/3/19
to sy...@googlegroups.com

Use slicing like q[:,0]

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e3949e3d-12d0-4154-865a-6b5b0c42b203%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

S.Y. Lee

unread,
May 3, 2019, 4:05:53 AM5/3/19
to sympy
Matrices are mutable as default in SymPy.
You would either have to copy

>>> from sympy import *

>>> q = Matrix([[x,x+1],[x-1,x+2]])
>>> w = q.copy()
>>> w.col_del(0)

Or use ImmutableMatrix

>>> from sympy import *

>>> q = ImmutableDenseMatrix([[x,x+1],[x-1,x+2]])
>>> w = q
>>> w1 = w.col_del(0)

Python lists also have the same philosophy, so you would have to use mutable ones carefully.

mura...@erzurum.edu.tr

unread,
May 3, 2019, 6:20:51 AM5/3/19
to sympy
q.copy() works. Thank you very much!

3 Mayıs 2019 Cuma 11:01:36 UTC+3 tarihinde Kalevi Suominen yazdı:
Perhaps you should make a copy of q:  w = q.copy().

Kalevi Suominen

Reply all
Reply to author
Forward
0 new messages