使用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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。