Thank you very much! Indeed, now it works! Il giorno giovedì 5 marzo 2020 12:55:21 UTC+1, Oscar ha scritto: > > On Thu, 5 Mar 2020 at 11:30, Lorenzo Monacelli > <[email protected] <javascript:>> wrote: > > > > Dear all, > > I would like to implement some basic manipulation with matrices that I > need. > > The problem I'm facing is that I cannot figure out how to recognize > correctly a MatrixSymbol: > > from sympy.abc import i,j > > A = sy.MatrixSymbol("A",3,3) > > B = sy.MatrixSymbol("B",3,3) > > C = sy.MatrixSymbol("C",3,3) > > > > pippo = A[i,j].subs(A, B+C) > > isinstance(pippo.args[0].args[0].func, sy.MatrixSymbol) # False > > isinstance(B.func, sy.MatrixSymbol) #True > > The .func attribute gives MatrixSymbol so you could use: > > pippo.args[0].args[0].func is sy.MatrixSymbol > > or (note no .func): > > isinstance(pippo.args[0].args[0], sy.MatrixSymbol) > > > Note, that pippo.args[0].args[0] is B and if you print > pippo.args[0].args[0].func it returns > > sympy.matrices.expressions.matexpr.MatrixSymbol > > > > So why is it not working? > > Because you are asking if MatrixSymbol is an instance of itself: > > In [11]: isinstance(MatrixSymbol, MatrixSymbol) > Out[11]: False > > -- > Oscar >
-- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/fe9febb6-588f-4e3b-8c71-c192dbc58456%40googlegroups.com.
