使用count_ops()
在simpy模块中的方法中,我们可以计算数学函数中使用的运算次数。count_ops()
方法返回数学函数中使用的运算数。
Syntax:sympy.count_ops() Return:the count of operations.
代码1:
借助以下示例,我们可以清楚地了解使用 sympy.count_ops()
方法,我们可以计算给定表达式中的操作数。
# importing sympy library
from sympy import *
# taking symbols
x, y, z = symbols('x y z')
# calling count_ops() method on expression
geek = sqrt((x + 1)**2 + x).count_ops()
print(geek)
输出:
5
代码2:
# importing sympy library
from sympy import *
# taking symbols
a, b = symbols('a b')
# calling count_ops() method on expression
geek = log(a) + log(b) + log(a)*log(1 / b)
print(count_ops(geek))
输出:
8
代码3:
# importing sympy library
from sympy import *
# taking symbols
a, b = symbols('a b')
# calling count_ops() method on expression
geek = log(a * b**(1 - log(a)))
print(count_ops(geek))
输出:
5
相关用法
- Python next()用法及代码示例
- Python os.dup()用法及代码示例
- Python set()用法及代码示例
- Python Decimal max()用法及代码示例
- Python PIL ImageOps.fit()用法及代码示例
- Python os.rmdir()用法及代码示例
- Python sympy.det()用法及代码示例
- Python Decimal min()用法及代码示例
- Python os.readlink()用法及代码示例
- Python os.writev()用法及代码示例
- Python os.readv()用法及代码示例
- Python PIL RankFilter()用法及代码示例
- Python os.rename()用法及代码示例
- Python os.sendfile()用法及代码示例
注:本文由纯净天空筛选整理自Shivam_k大神的英文原创作品 Python | sympy.count_ops() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。