SciPy Constants Module
SciPy's constants module provides many built-in mathematical constants.
Pi is a mathematical constant, the ratio of a circle's circumference to its diameter, approximately equal to 3.14159, commonly denoted by the symbol .
The following example outputs pi:
Example
from
scipy
import
constants
(
constants.
pi
)
After executing the above code, the output is as follows:
3.141592653589793
The following example outputs the golden ratio:
Example
from
scipy
import
constants
(
constants.
golden
)
After executing the above code, the output is as follows:
1.618033988749895
We can use the dir() function to see constants which constants the module contains:
Example
from
scipy
import
constants
(
dir
(
constants
)
)
After executing the above code, the output is as follows:
['Avogadro', 'Boltzmann', 'Btu', ...]
Unit Types
The constants module contains the following unit types:
- Metric Units
- Binary, in bytes
- Mass Units
- Angle Conversion
- Time Units
- Length Units
- Pressure Units
- Volume Units
- Speed Units
- Temperature Units
- Energy Units
- Power Units
- Mechanical Units
SI Prefixes
SI prefixes (English: SI prefix) denote multiples and fractions of units; there are currently 20 prefixes, most of which are integer powers of one thousand. (centi returns 0.01):
|
yotta
| | --- | --- | |
zetta
| |
exa
| |
peta
| |
tera
| |
giga
| |
mega
| |
kilo
| |
hecto
| |
deka
| |
deci
| |
centi
| |
milli
| |
micro
| |
nano
| |
pico
| |
femto
| |
atto
| |
zepto
|
Example
from
scipy
import
constants
(
constants.
yotta
)
#1e+24
(
constants.
zetta
)
#1e+21
(
constants.
exa
)
#1e+18
(
constants.
peta
)
#1000000000000000.0
(
constants.
tera
)
#1000000000000.0
(
constants.
giga
)
#1000000000.0
(
constants.
mega
)
#1000000.0
(
constants.
kilo
)
#1000.0
(
constants.
hecto
)
#100.0
(
constants.
deka
)
#10.0
(
constants.
deci
)
#0.1
(
constants.
centi
)
#0.01
(
constants.
milli
)
#0.001
(
constants.
micro
)
#1e-06
(
constants.
nano
)
#1e-09
(
constants.
pico
)
#1e-12
(
constants.
femto
)
#1e-15
(
constants.
atto
)
#1e-18
(
constants.
zepto
)
#1e-21
Binary Prefixes
Returns the value in bytes (kibi returns 1024).
|
kibi
| | --- | --- | |
mebi
| |
gibi
| |
tebi
| |
pebi
| |
exbi
| |
zebi
| |
yobi
|
Example
from
scipy
import
constants
(
constants.
kibi
)
#1024
(
constants.
mebi
)
#1048576
(
constants.
gibi
)
#1073741824
(
constants.
tebi
)
#1099511627776
(
constants.
pebi
)
#1125899906842624
(
constants.
exbi
)
#1152921504606846976
(
constants.
zebi
)
#1180591620717411303424
(
constants.
yobi
)
#1208925819614629174706176
Mass Units
Returns how many kilograms kg. (gram returns 0.001).
Example
from
scipy
import
constants
(
constants.
gram
)
#0.001
(
constants.
metric_ton
)
#1000.0
(
constants.
grain
)
#6.479891e-05
(
constants.
lb
)
#0.45359236999999997
(
constants.
pound
)
#0.45359236999999997
(
constants.
oz
)
#0.028349523124999998
(
constants.
ounce
)
#0.028349523124999998
(
constants.
stone
)
#6.3502931799999995
(
constants.
long_ton
)
#1016.0469088
(
constants.
short_ton
)
#907.1847399999999
(
constants.
troy_ounce
)
#0.031103476799999998
(
constants.
troy_pound
)
#0.37324172159999996
(
constants.
carat
)
#0.0002
(
constants.
atomic_mass
)
#1.66053904e-27
(
constants.
m_u
)
#1.66053904e-27
(
constants.
u
)
#1.66053904e-27
Angle Units
Returns radians (degree returns 0.017453292519943295).
Example
from
scipy
import
constants
(
constants.
degree
)
#0.017453292519943295
(
constants.
arcmin
)
#0.0002908882086657216
(
constants.
arcminute
)
#0.0002908882086657216
(
constants.
arcsec
)
#4.84813681109536e-06
(
constants.
arcsecond
)
#4.84813681109536e-06
Time Units
Returns the number of seconds (hour returns 3600.0).
Example
from
scipy
import
constants
(
constants.
minute
)
#60.0
(
constants.
hour
)
#3600.0
(
constants.
day
)
#86400.0
(
constants.
week
)
#604800.0
(
constants.
year
)
#31536000.0
(
constants.
Julian_year
)
#31557600.0
Length Units
Returns the number of meters (nautical_mile returns 1852.0).
Example
from
scipy
import
constants
(
constants.
inch
)
#0.0254
(
constants.
foot
)
#0.30479999999999996
(
constants.
yard
)
#0.9143999999999999
(
constants.
mile
)
#1609.3439999999998
(
constants.
mil
)
#2.5399999999999997e-05
(
constants.
pt
)
#0.00035277777777777776
(
constants.
point
)
#0.00035277777777777776
(
constants.
survey_foot
)
#0.3048006096012192
(
constants.
survey_mile
)
#1609.3472186944373
(
constants.
nautical_mile
)
#1852.0
(
constants.
fermi
)
#1e-15
(
constants.
angstrom
)
#1e-10
(
constants.
micron
)
#1e-06
(
constants.
au
)
#149597870691.0
(
constants.
astronomical_unit
)
#149597870691.0
(
constants.
light_year
)
#9460730472580800.0
(
constants.
parsec
)
#3.0856775813057292e+16
Pressure Units
Returns how many pascals, the SI unit of pressure. (psi returns 6894.757293168361).
Example
from
scipy
import
constants
(
constants.
atm
)
#101325.0
(
constants.
atmosphere
)
#101325.0
(
constants.
bar
)
#100000.0
(
constants.
torr
)
#133.32236842105263
(
constants.
mmHg
)
#133.32236842105263
(
constants.
psi
)
#6894.757293168361
Area Units
Returns how many square meters; the square meter is the metric unit of area, defined as:the area of a square with a side length of one meter on a plane. (hectare returns 10000.0).
Example
from
scipy
import
constants
(
constants.
hectare
)
#10000.0
(
constants.
acre
)
#4046.8564223999992
Volume Units
Returns how many cubic meters; the cubic meter is a unit of volume. A volume of 1 cubic meter equals the volume of a cube whose length, width, and height are all 1 meter, equal to 1 kiloliter and 1 ton of water, and also equal to 1,000,000 cubic centimeters. (liter returns 0.001).
Example
from
scipy
import
constants
(
constants.
liter
)
#0.001
(
constants.
litre
)
#0.001
(
constants.
gallon
)
#0.0037854117839999997
(
constants.
gallon_US
)
#0.0037854117839999997
(
constants.
gallon_imp
)
#0.00454609
(
constants.
fluid_ounce
)
#2.9573529562499998e-05
(
constants.
fluid_ounce_US
)
#2.9573529562499998e-05
(
constants.
fluid_ounce_imp
)
#2.84130625e-05
(
constants.
barrel
)
#0.15898729492799998
(
constants.
bbl
)
#0.15898729492799998
Speed Units
Returns meters per second. (speed_of_sound returns 340.5).
Example
from
scipy
import
constants
(
constants.
kmh
)
#0.2777777777777778
(
constants.
mph
)
#0.44703999999999994
(
constants.
mach
)
#340.5
(
constants.
speed_of_sound
)
#340.5
(
constants.
knot
)
#0.5144444444444445
Temperature Units
Returns how many kelvin. (zero_Celsius returns 273.15).
Example
from
scipy
import
constants
(
constants.
zero_Celsius
)
#273.15
(
constants.
degree_Fahrenheit
)
#0.5555555555555556
Energy Units
Returns how many joules; the joule (abbreviated J) is a derived unit of energy, work, or heat in the SI system, with symbol J. (calorie returns 4.184).
Example
from
scipy
import
constants
(
constants.
zero_Celsius
)
#273.15
(
constants.
degree_Fahrenheit
)
#0.5555555555555556
Power Units
Returns how many watts; the watt (symbol: W) is the SI unit of power. One watt is defined as 1 joule/second (1 J/s), that is, the rate of energy converted, used, or dissipated (measured in amperes) per second. (horsepower returns 745.6998715822701).
Example
from
scipy
import
constants
(
constants.
hp
)
#745.6998715822701
(
constants.
horsepower
)
#745.6998715822701
Mechanical Units
Returns how many newtons; the newton (symbol N, English: Newton) is a physical dimension and the metric unit of force. It is named after Isaac Newton, who established classical mechanics. (kilogram_force returns 9.80665).
Example
from
scipy
import
constants
(
constants.
dyn
)
#1e-05
(
constants.
dyne
)
#1e-05
(
constants.
lbf
)
#4.4482216152605
(
constants.
pound_force
)
#4.4482216152605
(
constants.
kgf
)
#9.80665
(
constants.
kilogram_force
)
#9.80665