Selected Reading

SciPy - precision() Method



The SciPy precision() method is used to access the information about physical constants which contain the values and units. A physical constant is considered as the theoretical equation of physics which describes the various units and values of invariant quantities such as the speed of light in vacuum (speed_of_light), the plank constant (Planck constant), elementary charge (e), etc.

Syntax

Following is the syntax of the SciPy precision() method −

precision(key)

Parameters

This function takes a single parameter −

  • key: This parameter is acts as an string that specify the physical constant.

Return value

This method returns the float values.

Example 1

Following is the basic SciPy precision() method that illustrates the usage of physical constant. Here, we denote the physical constant as "speed of light in vacuum."

from scipy.constants import physical_constants

key = 'speed of light in vacuum'
precision = physical_constants[key][1]

print(f"The uncertainty of {key} is {precision}.")

Output

The above code produces the following result −

The uncertainty of speed of light in vacuum is m s^-1.

Example 2

Here, we perform the physical constants as "Planck constant" that shows the result.

from scipy.constants import physical_constants

key = 'Planck constant'
precision = physical_constants[key][1]
print(f"The uncertainty of {key} is {precision}.")

Output

The above code produces the following result −

The uncertainty of Planck constant is J Hz^-1.

Example 3

This program prints the result of dictionary which contain the tuple forms(value, unit, and uncertainty) for each physical constant.

from scipy.constants import physical_constants

key = 'Newtonian constant of gravitation'
value, unit, uncertainty = physical_constants[key]

print(f"The uncertainty of {key} is approximately {uncertainty:.2e} {unit}.")

Output

The above code produces the following result −

The uncertainty of Newtonian constant of gravitation is approximately 1.50e-15 m^3 kg^-1 s^-2.

Example

In this example, we will get the result proton mass using precision() method.

from scipy import constants
result = constants.precision('proton mass')
print("Proton Mass : ", result)

Output

The above code produces the following result −

Proton Mass :  3.0491050773439597e-10
scipy_reference.htm
Advertisements