Python | sympy.replace() method
Last Updated :
26 Jul, 2019
With the help of sympy.replace()
method, we can replace the functions in the mathematical expression without editing the whole expression by using sympy.replace()
method.
Syntax : sympy.replace()
Return : Return the replaced values in the mathematical expression.
Example #1 :
In this example we can see that by using sympy.replace()
method, we are able to replace the mathematical functions in the expression and return the updated expression.
from sympy import *
x, y = symbols( 'x y' )
f = sin(x) + cos( 2 * x)
gfg = f.replace(cos, sin)
print (gfg)
|
Output :
sin(x) + sin(2*x)
Example #2 :
from sympy import *
x, y = symbols( 'x y' )
f = log(sin(x)) + tan(cos( 2 * x))
gfg = f.replace(log, tan)
print (gfg)
|
Output :
tan(sin(x)) + tan(cos(2*x))
Share your thoughts in the comments
Please Login to comment...