Home > OS >  How to convert a number multiplied by a symbol to integer in sympy?
How to convert a number multiplied by a symbol to integer in sympy?

Time:07-22

for example:

((360/2)*x)/2 # output : 90.0*x
# I want the output to be : 90*x
int(((360/2)*x)/2) # TypeError

Is there any function that I can use to convert 90.0x to 90x

CodePudding user response:

You can use xreplace to go through your expression and make the changes:

>>> eq
2.0*x
>>> eq.xreplace({i: int(i) for i in eq.atoms(Float) if i == int(i)})
2*x

CodePudding user response:

Thanks to @OscarBenjamin

nsimplify(((360/2)*x)/2) # output : 90*n
  • Related