On Thu, 5 Mar 2020 at 11:30, Lorenzo Monacelli
<[email protected]> 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/CAHVvXxR6zz9h9vgnbYgw%2B5aF7X0ECUYRoGSw0sWWi6KgrcjjJg%40mail.gmail.com.

Reply via email to