SciPy – Constants

SciPy constants package provides a wide range of constants, which are used in the general scientific area.

SciPy Constants Package

The scipy.constants package provides various constants. We have to import the required constant and use them as per the requirement. Let us see how these constant variables are imported and used.

To start with, let us compare the ‘pi’ value by considering the following example.

#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)

The above program will generate the following output.

sciPy - pi = 3.1415926535897931
math - pi = 3.1415926535897931

List of Constants Available

The following tables describe in brief the various constants.

Mathematical Constants

Sr. No.ConstantDescription
1pipi
2goldenGolden Ratio

Physical Constants

The following table lists the most commonly used physical constants.

Sr. No.Constant & Description
1cSpeed of light in vacuum
2speed_of_lightSpeed of light in vacuum
3hPlanck constant
4PlanckPlanck constant h
5GNewton’s gravitational constant
6eElementary charge
7RMolar gas constant
8AvogadroAvogadro constant
9kBoltzmann constant
10electron_mass(OR) m_eElectronic mass
11proton_mass (OR) m_pProton mass
12neutron_mass(OR)m_nNeutron mass

Units

The following table has the list of SI units.

Sr. No.UnitValue
1milli0.001
2micro1e-06
3kilo1000

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.

Sr. No.UnitValue
1gram0.001 kg
2atomic massAtomic mass constant
3degreeDegree in radians
4minuteOne minute in seconds
5dayOne day in seconds
6inchOne inch in meters
7micronOne micron in meters
8light_yearOne light-year in meters
9atmStandard atmosphere in pascals
10acreOne acre in square meters
11literOne liter in cubic meters
12gallonOne gallon in cubic meters
13kmhKilometers per hour in meters per seconds
14degree_FahrenheitOne Fahrenheit in kelvins
15eVOne electron volt in joules
16hpOne horsepower in watts
17dynOne dyne in newtons
18lambda2nuConvert wavelength to optical frequency

Remembering all of these are a bit tough. The easy way to get which key is for which function is with the scipy.constants.find() method. Let us consider the following example.

import scipy.constants
res = scipy.constants.physical_constants["alpha particle mass"]
print res

The above program will generate 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 the list of keys, else nothing if the keyword does not match.

This Post Has One Comment

Leave a Reply