我们如何使用 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
广告