我們如何使用 scipy 庫中的各種數學和物理常量?
為了實現科學或數學計算,我們需要各種通用常量。例如,計算圓形面積的公式為 pi*r*r,其中 Pi 是一個值為 = 3.141592653 的常量。還有許多類似這樣的場景,我們需要常量。如果我們能輕鬆地將這些常量納入我們的計算,那將非常有幫助。Scipy 庫中的一個子模組 scipy.constants() 為我們完成這項工作,併為我們提供一個參考材料,用於查詢物理常數、通用數學常數以及國際單位制字首、二進位制字首、質量、角度、時間等各種單位的詳盡列表。
我們可以透過在 scipy.constants.name_of_constant 中鍵入常量名稱來訪問任何常量的值。例如,如果您想訪問常量 Pi 的值,請輸入 scipy.constants.pi。
示例
#Importing the module
from scipy import constants
#Printing the values of constants
print("The value of sciPy - pi = ", constants.pi)
print("The value of Golden ratio = ", constants.golden_ratio)
print("The value of Speed of light in vaccum = ", constants.c)
print("The value of Gravitational Constant = ", constants.G)
print("The value of Molar Gas Constant = ", constants.R)
print("The value of Boltzman Constant = ", constants.k)
print("The value of Proton mass Constant = ", constants.proton_mass)輸出
The value of sciPy - pi = 3.141592653589793 The value of Golden ratio = 1.618033988749895 The value of Speed of light in vaccum = 299792458.0 The value of Gravitational Constant = 6.6743e-11 The value of Molar Gas Constant = 8.314462618 The value of Boltzman Constant = 1.380649e-23 The value of Proton mass Constant = 1.67262192369e-27
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP