Python | sympy.count_ops() method
Last Updated :
19 Jul, 2019
Using the count_ops()
method in simpy module, we can count the number of operations used in the mathematical function. count_ops()
method returns the number of operations used in the mathematical function.
Syntax : sympy.count_ops()
Return : the count of operations.
Code #1:
With the help of below examples, we can clearly understand that using sympy.count_ops()
method we can count the number of operations in given expression.
from sympy import *
x, y, z = symbols( 'x y z' )
geek = sqrt((x + 1 ) * * 2 + x).count_ops()
print (geek)
|
Output:
5
Code #2:
from sympy import *
a, b = symbols( 'a b' )
geek = log(a) + log(b) + log(a) * log( 1 / b)
print (count_ops(geek))
|
Output:
8
Code #3:
from sympy import *
a, b = symbols( 'a b' )
geek = log(a * b * * ( 1 - log(a)))
print (count_ops(geek))
|
Output:
5
Share your thoughts in the comments
Please Login to comment...