- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we use various mathematical and physical constants in scipy library?
To implement Scientific or Mathematical calculation, we need various universal constants. For example, the formula to calculate area of a circle is pi*r*r where Pi is a constant having value = 3.141592653. There are various other scenarios like this where we need constants. It would really be helpful if we can incorporate these constants into our calculation with ease. The scipy.constants(), a sub-module inside the Scipy library, does the job for us and provide us a reference material to look up exhaustive list of Physical Constants, universal mathematical constants, and various units such as SI prefixes, Binary prefixes, Mass, Angle, Time, etc.
We can access the value of any constant by typing the name of the constant in scipy.constants.name_of_constant. For example, if you want to access the value of constant Pi, type scipy.constants.pi.
Example
#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)
Output
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