I think that this is a gotcha with Python.
Python already returns False when checking out isinstance(int, int).
And in general OOP theory, class and instance should be different.
If you want to compare the class by class, then comparing with == or
issubclass should suffice.
On Thursday, March 5, 2020 at 8:30:24 PM UTC+9, Lorenzo Monacelli 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
> 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? How can I check if it is a matrix and stop the
> recursion?
>
> Bests,
> Lorenzo
>
--
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/4f10eb5c-4158-41cd-9476-8ea52aaeaeff%40googlegroups.com.