subs function giving me error message

30 views
Skip to first unread message

Adam S

unread,
Jun 28, 2016, 11:22:35 AM6/28/16
to sympy
Hi,
I am getting confused on Python 3 error message using subs:

from sympy import *
x, y = symbols('x y')
fun = cos(x) + 1
fun.subs(x,y)

--> cos(y) + 1

which is okay. It does at it should.

from sympy import *
x, y = symbols('x y')
fun2=1
fun2.subs(x,y)

--> Attribute error: 'int' object has not attribute 'subs'

What is the failure here?  How to fix this?  I used sympy online and it works, but on desktop it does not.  Why?

I used recently anaconda to download python 3 and other libraries etc.

Aaron Meurer

unread,
Jun 28, 2016, 12:49:39 PM6/28/16
to sy...@googlegroups.com
If your expression is a pure Python integer or float, you have to
convert it to a SymPy type first to use SymPy methods on it. So

fun2 = Integer(1)

will work. In general, you can use sympify(), or the shorter S() to
convert things to SymPy types.

It works in the SymPy Live online shell because that shell wraps
integers with Integer() automatically.

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 post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/eec9cfdd-1b15-4b3d-8541-a7a2ea157b6a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages