Scipy 简明教程
SciPy - Constants
SciPy 常量包提供了广泛的常量,可用于一般科学领域。
SciPy Constants Package
scipy.constants package 提供各种常量。我们必须导入所需的常量,并根据要求使用。让我们看看如何导入和使用这些常量变量。
首先,让我们考虑以下示例,比较“pi”值。
#Import pi constant from both the packages
from scipy.constants import pi
from math import pi
print("sciPy - pi = %.16f"%scipy.constants.pi)
print("math - pi = %.16f"%math.pi)
上述程序将生成以下输出。
sciPy - pi = 3.1415926535897931
math - pi = 3.1415926535897931
List of Constants Available
下表简要介绍了各种常量。
Physical Constants
下表列出了最常用的物理常量。
Sr. No. |
Constant & Description |
1 |
c 真空中光速 |
2 |
speed_of_light 真空中光速 |
3 |
h Planck constant |
4 |
Planck Planck constant h |
5 |
G Newton’s gravitational constant |
6 |
e Elementary charge |
7 |
R Molar gas constant |
8 |
Avogadro Avogadro constant |
9 |
k Boltzmann constant |
10 |
electron_mass(OR) m_e Electronic mass |
11 |
proton_mass (OR) m_p Proton mass |
12 |
neutron_mass(OR)m_n Neutron mass |
Units
下表列出了国际单位制。
Sr. No. |
Unit |
Value |
1 |
milli |
0.001 |
2 |
micro |
1e-06 |
3 |
kilo |
1000 |
这些单位的范围从尧、泽、艾、拍、太……千、百……纳、皮……到泽普托。
Other Important Constants
下表列出了 SciPy 中使用的其他重要常量。
Sr. No. |
Unit |
Value |
1 |
gram |
0.001 kg |
2 |
atomic mass |
Atomic mass constant |
3 |
degree |
Degree in radians |
4 |
minute |
One minute in seconds |
5 |
day |
One day in seconds |
6 |
inch |
One inch in meters |
7 |
micron |
One micron in meters |
8 |
light_year |
One light-year in meters |
9 |
atm |
Standard atmosphere in pascals |
10 |
acre |
一英亩多少平方米 |
11 |
liter |
一升多少立方米 |
12 |
gallon |
一加仑多少立方米 |
13 |
kmh |
每小时多少千米每秒 |
14 |
degree_Fahrenheit |
One Fahrenheit in kelvins |
15 |
eV |
一电子伏特多少焦耳 |
16 |
hp |
One horsepower in watts |
17 |
dyn |
One dyne in newtons |
18 |
lambda2nu |
将波长转换为光频 |
记住所有这些有点困难。获取哪个键适用于哪个函数的简单方法是使用 scipy.constants.find() 方法。让我们考虑以下示例。
import scipy.constants
res = scipy.constants.physical_constants["alpha particle mass"]
print res
上述程序将生成以下输出。
[
'alpha particle mass',
'alpha particle mass energy equivalent',
'alpha particle mass energy equivalent in MeV',
'alpha particle mass in u',
'electron to alpha particle mass ratio'
]
此方法返回键的列表,否则如果关键字不匹配,则返回空。