Scipy Constants – Multiple Examples

In this Python tutorial, we will learn about the “Scipy Constants” where we will know about the different types of constants in Scipy. Additionally, cover the following topics.

  • Scipy Constants Python
  • Scipy Constants Units
  • Scipy Constants list
  • Scipy Constants C
  • Scipy Constants epsilon 0
  • Scipy Constants find
  • Scipy Constants hbar
  • Scipy Constants mu0
  • Scipy Constants speed of light
  • Scipy Constants Rydberg
  • Scipy Constants Temperature

Scipy Constants Python

The Scipy Constants is a Python sub-package that contains many different types of constants for scientific domains. These constants can be used according to our needs in Data Science, Deep Learning, and Machine Learning.

There are three types of constants in Scipy:

  • Physical constants: The Physical constants are the speed of light in a vacuum (c), the magnetic constant (mu_0), etc.
  • Mathematical constants: The Mathematical constants are Pi (pi), Golden ratio (golden), and (golden_ratio).
  • Units: The Units are Mass, Time, Angle, etc.

Later in the below sub-sections, we will learn about each constant separately.

Here we will use the Jupyter Notebook for the demonstration of how to import and use the Scipy Constants.

Open Jupyter Notebook and type the below code in the cell to import the Scipy Constants.

import scipy.constants as constant
Scipy Constants Python
Scipy Constants Python

Let’s check the value of some of Scipy’s constants.

Check the value of the Mathematical Constant Pi using the below code.

print(constant.pi)

Check the value of the Physical Constant speed of light using the below code.

print(constant.speed_of_light)

Check the value of the Unigram using the below code.

print(constant.gram)
Scipy Constant
Scipy Constant

Also, check: What is Scikit Learn in Python

Scipy Constants Units

Here we will learn about the Scipy Units, there are 15 types of Units in Scipy and each type contains its constants.

The type of Units in Scipy is given below.

  • Angle
  • Mass
  • SI prefixes
  • Binary prefixes
  • Time
  • Length
  • Pressure
  • Volume
  • Speed
  • Area
  • Temperature
  • Energy
  • Power
  • Optics
  • Force

Angle

The Angle Units has constants like degree, arcmin, arcminute, arcsec and arcsecond. These constants have units value in radians.

Run the below code to see the value of all the constants in Angle.

print('The value of degree in radians :',const.degree)     
print('The value of arc minute in radians :',const.arcmin)    
print('The value of arc minute in radians :',const.arcminute) 
print('The value of arc second in radians :',const.arcsec)    
print('The value of arc second in radians :',const.arcsecond)
Scipy Constants Units Angle
Scipy Constants Units Angle

Mass

The Mass Unit has constants like gram, metric, grain, etc. It returns the unit value in a kg. All the constant is shown below using the code.

Run the below code to see all the values of contacts in Mass.

print('The value of gram is equal to 10 to the power -3 in kg :',const.gram)        
print('The value of gram is equal to 10 to the power 3 in kg :',const.metric_ton)  
print('The value of one grain in kg :',const.grain)       
print('The value of one pound in kg :',const.lb)          
print('The value of one pound in kg :',const.pound)       
print('The value of one ounce in kg :',const.oz)          
print('The value of one ounce in kg :',const.ounce)       
print('The value of one stone in kg :',const.stone)
print('The value of one slug in kg :',const.slug)
print('The value of one long ton in kg :',const.long_ton)    
print('The value of one short ton in kg :',const.short_ton)
print('The value of one inch version of a slug in kg :',const.slinch)
print('The value of one inch version of a slug in kg :',const.blob)
print('The value of one troy ounce in kg :',const.troy_ounce)  
print('The value of one troy pound in kg :',const.troy_pound)  
print('The value of one carat in kg :',const.carat)       
print('The value of one atomic mass constant in kg :',const.atomic_mass) 
print('The value of one atomic mass constant in kg :',const.m_u)         
print('The value of one atomic mass constant in kg :',const.u)
Scipy Constants Units Mass
Scipy Constants Units Mass

Read Scipy Optimize

SI Prefixes

The SI Prefixes Unit has constants like Zetta, Yotta, Peta, etc. It returns the unit value in a meter. All the constant is shown below using the code.

print('The value of yotta is equal to 10 to the power 24 :',const.yotta)    
print('The value of zetta is equal to 10 to the power 21 :',const.zetta)    
print('The value of exa is equal to 10 to the power 18 :',const.exa)      
print('The value of peta is equal to 10 to the power 15 :',const.peta)     
print('The value of tera is equal to 10 to the power 12 :',const.tera)     
print('The value of giga is equal to 10 to the power 9 :',const.giga)     
print('The value of mega is equal to 10 to the power 6 :',const.mega)     
print('The value of kilo is equal to 10 to the power 3 :',const.kilo)     
print('The value of hecto is equal to 10 to the power 2 :',const.hecto)    
print('The value of deka is equal to 10 to the power 1 :',const.deka)     
print('The value of deci is equal to 10 to the power -1 :',const.deci)     
print('The value of centi is equal to 10 to the power -2 :',const.centi)    
print('The value of milli is equal to 10 to the power -3 :',const.milli)    
print('The value of micro is equal to 10 to the power -6 :',const.micro)
print('The value of nano is equal to 10 to the power -9 :',const.nano) 
print('The value of pico is equal to 10 to the power -12 :',const.pico)   
print('The value of femto is equal to 10 to the power -15 :',const.femto) 
print('The value of atto is equal to 10 to the power -18 :',const.atto)
print('The value of zepto is equal to 10 to the power -21 :',const.zepto)
print('The value of yocto is equal to 10 to the power -24 :',const.yocto)
Scipy Constants Units SI prefixes
Scipy Constants Units SI prefixes

Binary Prefixes

The Binary Prefixes Unit has constants like gibi, pebi, mebi, etc. It returns the unit value in bytes. All the constant is shown below using the code.

print('The value of kibi is equal to 2 to the power 10 :',const.kibi)
print('The value of kibi is equal to 2 to the power 20 :',const.mebi)
print('The value of kibi is equal to 2 to the power 30 :',const.gibi) 
print('The value of kibi is equal to 2 to the power 40 :',const.tebi) 
print('The value of kibi is equal to 2 to the power 50 :',const.pebi) 
print('The value of kibi is equal to 2 to the power 60 :',const.exbi) 
print('The value of kibi is equal to 2 to the power 70 :',const.zebi) 
print('The value of kibi is equal to 2 to the power 80 :',const.yobi) 
Scipy Constants Units Binary prefixes
Scipy Constants Units Binary prefixes

Time

The Time Unit has constants like a minute, day, hour, etc. It returns the unit value in seconds. All the constant is shown below using the code.

print('The value of one minute in seconds :',const.minute)
print('The value of one hour in seconds :',const.hour)
print('The value of one day in seconds :',const.day) 
print('The value of one week in seconds :',const.week)  
print('The value of one year in seconds :',const.year) 
print('The value of one Julian_year in seconds :',const.Julian_year)
Scipy Constants Units Time
Scipy Constants Units Time

Length

The Length Unit has constants like a foot, mile, fermi, etc. It returns the unit value in meters. All the constant is shown below using the code.

print('The value of one inch in meters :',const.inch)
print('The value of one foot in meters :',const.foot) 
print('The value of one yard in meters :',const.yard) 
print('The value of one mile in meters :',const.mile) 
print('The value of one mil in meters :',const.mil) 
print('The value of one pt in meters :',const.pt) 
print('The value of one point in meters :',const.point)  
print('The value of one survey foot in meters :',const.survey_foot)  
print('The value of one survey mile in meters :',const.survey_mile) 
print('The value of one nautical mile in meters :',const.nautical_mile)  
print('The value of one fermi in meters :',const.fermi)
print('The value of one angstrom in meters :',const.angstrom)
print('The value of one micron in meters :',const.micron) 
print('The value of one astronomical unit in meters :',const.au)
print('The value of one astronomical unit in meters :',const.astronomical_unit) 
print('The value of one light year in meters :',const.light_year)        
print('The value of one parsec in meters :',const.parsec)
Scipy Constants Units Length
Scipy Constants Units Length

Pressure

The Pressure Unit has constants like psi, atm, bar, etc. It returns the unit value in pascals. All the constant is shown below using the code.

print('The value of standard atomsphere in pascals :',const.atm) 
print('The value of standard atomsphere in pascals :',const.atmosphere) 
print('The value of one bar in pascals :',const.bar) 
print('The value of one torr in pascals :',const.torr)  
print('The value of one torr in pascals :',const.mmHg) 
print('The value of one psi in pascals :',const.psi) 
Scipy Constants Units Pressure
Scipy Constants Units Pressure

Volume

The Volume Unit has constants like a gallon, litre, barrel, etc. It returns the unit value in cubic meters. All the constant is shown below using the code.

print('The value of one litre in cubic meters :',const.liter) 
print('The value of one litre in cubic meters :',const.litre)      
print('The value of one gallon (United States) in cubic meters :',const.gallon)         
print('The value of one gallon (United States) in cubic meters :',const.gallon_US)
print('The value of one gallon (United Kingdom) in cubic meters :',const.gallon_imp) 
print('The value of one fluid ounce (United States) in cubic meters :',const.fluid_ounce) 
print('The value of one fluid ounce (United States) in cubic meters :',const.fluid_ounce_US)
print('The value of one fluid ounce (United Kindom) in cubic meters :',const.fluid_ounce_imp)
print('The value of one barrel in cubic meters :',const.barrel)
print('The value of one barrel in cubic meters :',const.bbl)
Scipy Constants Units Volume
Scipy Constants Units Volume

Speed

The Speed Unit has constants like mph, mach, knot, etc. It returns the unit value in meters per second. All the constant is shown below using the code.

print('The value of kmh kilometers per hour in meters per second :',const.kmh) 
print('The value of mph miles per hour in meters per second :',const.mph) 
print('The value of one mach meters per second :',const.mach) 
print('The value of one mach meters per second :',const.speed_of_sound) 
print('The value of one knot meters per second :',const.knot)       
Scipy Constants Units Speed
Scipy Constants Units Speed

Area

The Area Unit has constants like hectare, acre. It returns the unit value in square meters. All the constant is shown below using the code.

print('The value of one hectare in square meters :',const.hectare)
print('The value of one acre in square meters :',const.acre)
Scipy Constants Units Area
Scipy Constants Units Area

Temperature

The Temperature Unit has constants like zero_Celsius, degree_Fahrenheit. It returns the unit value in Kelvin. All the constant is shown below using the code.

print('The value of zero of celsius scale in Kelvin :',const.zero_Celsius)
print('The value of zero of fahrenheit scale in Kelvin :',const.degree_Fahrenheit)
Scipy Constants Units Temperature
Scipy Constants Units Temperature

Energy

The Energy Unit has constants like eV, calories, etc. It returns the unit value in Joules. All the constant is shown below using the code.

print('The value of one electron volt in Joules :',const.eV) 
print('The value of one electron volt in Joules :',const.electron_volt) 
print('The value of one calorie (Thermochemical) in Joules :',const.calorie) 
print('The value of one calorie (Thermochemical) in Joules :',const.calorie_th) 
print('The value of one calorie (International steam table calorie)in Joules :',const.calorie_IT) 
print('The value of one erg in Joules :',const.erg)  
print('The value of one british thermal unit in Joules :',const.Btu)  
print('The value of one british thermal unit (International steam table) in Joules :',const.Btu_IT)  
print('The value of one british thermal unit (International steam table) in Joules :',const.Btu_th)
print('The value of one ton of TNT in Joules :',const.ton_TNT)
Scipy Constants Units Energy
Scipy Constants Units Energy

Power

The Power Unit has constants like hp, horsepower. It returns the unit value in watts. All the constant is shown below using the code.

print('The value of one horsepower in watts :',const.hp) 
print('The value of one horsepower in watts :',const.horsepower)
Scipy Constants Units Power
Scipy Constants Units Power

Optics

The Optics Unit has constants lambda2nu( ) that return the optical frequency, and nu2lambda( ) that returns the wavelength.

Force

The Force Unit has constants like kgf, dyn, etc. It returns the unit value in newton. All the constant is shown below using the code.

print('The value of one dyne in newtons :',const.dyn)
print('The value of one dyne in newtons :',const.dyne)
print('The value of one pound force in newtons :',const.lbf)
print('The value of one pound force in newtons :',const.pound_force)
print('The value of one kilogram force in newtons :',const.kgf)
print('The value of one kilogram force in newtons :',const.kilogram_force)
Scipy Constants Units Force
Scipy Constants Units Force

Read: Tensorflow in Python

Scipy Constants list

To view or list all the constants in Scipy, for that we are going to use the function dir( ) , we pass the imported constants from Scipy to this function to view all the constants.

Here we are going to import the Scipy sub-package Constants using the below code.

import scipy.constants as const

Now pass the above-imported sub-package to a function dir( ).

print(dir(const))

Here in the above code function dir( ) accept the sub-package name const and show all constants within that package which is shown in the below output.

Scipy Constants list
Scipy Constants list

Read: What is PyTorch and how to use it

Scipy Constants C

In Scipy, the constants c represent the speed of light in a vacuum and it is a physical constant.

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of the constant speed of light in a vacuum.

print('The value of speed of light in vacuum :',cons.c)

Here, we can access the constant using cons.c.

Scipy Constants C
Scipy Constants C

The value of the speed of light in a vacuum which represented by constant c is 299792458.0.

Read: Machine Learning using Python

Scipy Constants epsilon 0

In Scipy, the epsilon 0 is an electric constant that exists within scipy.constants.

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of the electric constant using the below code.


print('The value of the electric constant :',cons.epsilon_0)

Here, we can access the constant using cons.epsilon_0.

Scipy Constants epsilon 0
Scipy Constants epsilon 0

Read: Scipy Sparse – Helpful Tutorial

Scipy Constants find

To get the keys to physical constants in Scipy, the method find( ) of scipy.constants are used.

The syntax is given below.

scipy.constants.find(sub_str=None, disp=False)

Where parameters are:

  • sub_str: It is substring or the name of physical constants whose keys we want to search.
  • dips: If it is set to True then found keys are returned, otherwise list all the keys without showing anything.

Let’s take an example of how to import and list the keys of physical constants using the below code.

from scipy.constants import find, physical_constants

Check the keys in physical constants containing a dictionary 'avogadro'.

find('avogadro')

List the constant 'Avogadro constant' using the below code.

physical_constants['Avogadro constant']
Scipy Constants find
Scipy Constants find

Read: Scipy Stats Zscore + Examples

Scipy Constants hbar

In Scipy, the constant hbar is a modified form of Planck’s constant that exists within scipy.constants whose value is equal to h= h/2pi).

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of Planck’s constant using the below code.

print('The value of Plancs constant :',cons.hbar)
Scipy Constants hbar
Scipy Constants hbar

Read: Python Scipy Minimize [With 8 Examples]

Scipy Constants mu0

In Scipy, the mu_0 is the magnetic constant that exists within scipy.constants.

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of the magnetic constant using the below code.

print('The value of the magnetic constant :',cons.mu_0)

Here, we can access the constant cons.mu_0.

Scipy Constants mu0
Scipy Constants mu0

Read: Python Scipy Confidence Interval

Scipy Constants speed of light

In Scipy, the constants speed_of_ligh represent the speed of light in a vacuum and it is a physical constant.

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of the constant speed of light in a vacuum.

print('The value of speed of light in vacuum :',cons.c)
Scipy Constants speed of light
Scipy Constants speed of light

Scipy Constants Rydberg

In Scipy, the constant Rydberg is Rydberg constant and it is a physical constant.

To import these constants follow the below steps:

import scipy.constants as cons

Check the value of the Rydberg constant.

print('The value of Rydberg constant :',cons.Rydberg)
Scipy Constants Rydberg
Scipy Constants Rydberg

Read: Python Scipy Exponential

Scipy Constants Temperature

The Temperature Unit has constants like zero_Celsius, degree_Fahrenheit. It returns the unit value in Kelvin. All the constant is shown below using the code.

print('The value of zero of celsius scale in Kelvin :',const.zero_Celsius)
print('The value of zero of fahrenheit scale in Kelvin :',const.degree_Fahrenheit)
Scipy Constants Units Temperature
Scipy Constants Units Temperature

Look at the value of both constants in the above output.

Also, take a look at some more tutorials.

In this tutorial, we have learned about the “Scipy Constants” and covered the following topics.

  • Scipy Constants Python
  • Scipy Constants Units
  • Scipy Constants list
  • Scipy Constants C
  • Scipy Constants epsilon 0
  • Scipy Constants find
  • Scipy Constants hbar
  • Scipy Constants mu0
  • Scipy Constants speed of light
  • Scipy Constants Rydberg
  • Scipy Constants Temperature