- SciPy 教程
- SciPy - 首頁
- SciPy - 簡介
- SciPy - 環境設定
- SciPy - 基本功能
- SciPy - 叢集
- SciPy - 常量
- SciPy - FFTpack
- SciPy - 積分
- SciPy - 插值
- SciPy - 輸入和輸出
- SciPy - 線性代數
- SciPy - Ndimage
- SciPy - 最佳化
- SciPy - 統計
- SciPy - CSGraph
- SciPy - 空間
- SciPy - ODR
- SciPy - 特殊包
- SciPy 有用資源
- SciPy - 參考
- SciPy - 快速指南
- SciPy - 有用資源
- SciPy - 討論
SciPy - precision() 方法
SciPy 的 precision() 方法用於訪問包含值和單位的物理常數資訊。**物理常數**被認為是物理學的理論方程,它描述了各種不變數的單位和值,例如真空中的光速 (speed_of_light)、普朗克常數 (Planck constant)、基本電荷 (e) 等。
語法
以下是 SciPy precision() 方法的語法:
precision(key)
引數
此函式接受一個引數:
- key:此引數充當字串,用於指定物理常數。
返回值
此方法返回浮點值。
示例 1
以下是基本的 SciPy precision() 方法,它說明了物理常數的使用。在這裡,我們將物理常數表示為“真空中的光速”。
from scipy.constants import physical_constants
key = 'speed of light in vacuum'
precision = physical_constants[key][1]
print(f"The uncertainty of {key} is {precision}.")
輸出
以上程式碼產生以下結果:
The uncertainty of speed of light in vacuum is m s^-1.
示例 2
在這裡,我們將物理常數作為“普朗克常數”進行操作,顯示結果。
from scipy.constants import physical_constants
key = 'Planck constant'
precision = physical_constants[key][1]
print(f"The uncertainty of {key} is {precision}.")
輸出
以上程式碼產生以下結果:
The uncertainty of Planck constant is J Hz^-1.
示例 3
此程式列印字典的結果,該字典包含每個物理常數的元組形式 (值、單位和不確定度)。
from scipy.constants import physical_constants
key = 'Newtonian constant of gravitation'
value, unit, uncertainty = physical_constants[key]
print(f"The uncertainty of {key} is approximately {uncertainty:.2e} {unit}.")
輸出
以上程式碼產生以下結果:
The uncertainty of Newtonian constant of gravitation is approximately 1.50e-15 m^3 kg^-1 s^-2.
示例
在此示例中,我們將使用 precision() 方法獲取質子質量的結果。
from scipy import constants
result = constants.precision('proton mass')
print("Proton Mass : ", result)
輸出
以上程式碼產生以下結果:
Proton Mass : 3.0491050773439597e-10
scipy_reference.htm
廣告