Muratani
Muratani

Reputation: 49

How to remove a column or a row of a matrix in SymPy with keeping the original one

I want to remove a column from the matrix and I want to keep original one but whenever I use command col_del() it deletes all columns of matrices even if I rename another one. For example:

q=sp.Matrix([[x,x+1],[x-1,x+2]])

display(q)

w=q

display(w)

w.col_del(0)

w1=w

display(w1)

display(w)

display(q)

If I delete column for w , it also deletes column of q which I want it to be unchanged. How can I keep the original one?

Upvotes: 0

Views: 1496

Answers (2)

Maarten Fabré
Maarten Fabré

Reputation: 7058

to understand what w=q means, I suggest you watch this talk by Brendan Rhodes. In short, w and q point to the same object, so removing something from the one, removes it from the other too

w = c.copy()

might solve your trouble

Upvotes: 1

RajmondX
RajmondX

Reputation: 415

Variables and Other References In Python

Change your code here:

w=q.copy()

SciPy numpy.matrix.copy

Upvotes: 0

Related Questions