SciPy constants
SciPy Constants
The SciPy constants package provides a large number of constants that are commonly used in scientific fields.
SciPy Constants Package
scipy.constants package provides various constants. We must import the required constants and use them as needed. Let’s see how these constant variables are imported and used.
First, let’s compare the value of “π” by considering the following example.
#Import pi constant from both packages
from scipy.constants import pi
from math import pi
print("sciPy - pi = %.16f"%scipy.constants.pi)
print("math - pi = %.16f"%math.pi)
The above program will produce the following output.
sciPy - pi = 3.1415926535897931
math - pi = 3.1415926535897931
List of Available Constants
The following table briefly describes the various constants.
Mathematical Constants
Sr. No. | Constant | Description |
---|---|---|
1 | pi | pi |
2 | golden | Golden Ratio |
Physical Constants
The following table lists the most commonly used physical constants.
Number | Constants and Descriptions |
---|---|
1 | c Speed of light in a vacuum |
2 | speed_of_light Speed of light in a vacuum |
3 | h Planck’s constant |
4 | Planck Planck’s 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 Electron mass |
11 | proton_mass (OR) m_p Proton mass |
12 | neutron_mass(OR)m_n Neutron mass |
Units
The following table contains a list of SI units.
Sr. No. | Unit | Value |
---|---|---|
1 | milli | 0.001 |
2 | micro | 1e-06 |
3 | kilo | 1000 |
These units range from yotta, zetta, exa, peta, tera, …kilo, hector, …nano, pico, …to zepto.
Other Important Constants
The following table lists other important constants used in SciPy.
Number: Sr. No. | Unit | Value |
---|---|---|
1 | Gram | 0.001 kilogram |
2 | Atomic mass | Atomic mass constant |
3 | Degrees | Degrees in radians |
4 | Minutes | One minute in seconds |
Day | A day in seconds | |
6 | Inch | One inch in meters |
7 | Micrometer | One micrometer in meters |
8 | Light-year | One light-year in meters |
9 | atm | Standard atmospheric pressure, in Pascals |
10 | Acres | One acre, in square meters |
11 | Liters | One liter, in cubic meters |
12 | Gallons | One gallon, in cubic meters |
13 | kmh | Kilometers per hour, in meters per second |
14 | Fahrenheit_Fahrenheit | One degree Fahrenheit, in Kelvin |
15 | eV | One electron volt, measured in joules |
16 | hp | One horsepower, measured in watts |
17 | Volt | One dean, measured in newtons |
18 | lambda2nu | Convert wavelength to light frequency |
It’s a bit difficult to remember all of this. An easy way to find out which key is which function is to use the scipy.constants.find() method. Let’s consider the following example.
import scipy.constants
res = scipy.constants.physical_constants["alpha particle mass"]
print res
The above program will produce the following output.
[
'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'
]
This method returns a list of keys, or nothing if the key does not match.