Python | sympy.replace() method
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.
# import sympy from sympy import * x, y = symbols('x y') f = sin(x) + cos(2 * x) # Use sympy.replace() method gfg = f.replace(cos, sin) print(gfg) |
Output :
sin(x) + sin(2*x)
Example #2 :
# import sympy from sympy import * x, y = symbols('x y') f = log(sin(x)) + tan(cos(2 * x)) # Use sympy.replace() method gfg = f.replace(log, tan) print(gfg) |
Output :
tan(sin(x)) + tan(cos(2*x))
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.waitid() method
- Python | shutil.which() method
- Python PIL | getpalette() Method
- Python PIL | getcolors() Method
- Python | os.WIFEXITED() method
- Python | Tensorflow cos() method
- Python | os.major() method
- Python | os.stat() method
- Python | os.minor() method
- Python | os.fstat() method
- Python | os.umask() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



