Can I use the method .subs() to replace a symbol with an object?

13 views
Skip to first unread message

Michele Cotrufo

unread,
Jun 29, 2020, 2:06:17 PM6/29/20
to sympy
I have an expression of the type

expr = x1

where x1 is a symbol.

I want to be able to replace x1 by a certain type of object, defined elsewhere. I tried something like

import sympy as sp
x1=  sp.symbols('x1')
obj1 = Obj()
expr=x1
expr.subs([(x1,obj1)])

but it doesn't perform any substitution.

Is it possible to use subs() with an arbitrary object, or is there a way around it?


Aaron Meurer

unread,
Jun 29, 2020, 2:27:30 PM6/29/20
to sympy
SymPy expressions can only contain Basic subclasses, so if your object
isn't a SymPy object, you will need to create a SymPy object that
wraps or represents it.

Aaron Meurer
> --
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/sympy/7ced1ea3-a275-472e-9c3b-5950cb000b98o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages