Python Tutorial

Introduction Python Features Python Applications System requirements for Python Python Installation Python Data Types Python IDE Python Keywords Python Operators Python Comments Python Pass Statement

Python Conditional Statements

Python if Statement Python elif Statement Python Switch Case

Python Loops

Python for loop Python while loop Python Break Statement Python Continue Statement Python Goto Statement

Python Arrays

Python Array Python Matrix

Python Strings

Python Strings Python Regex

Python Built-in Data Structure

Python Lists Python Tuples Python Dictionary Python Sets

Python Functions

Python Function Python min() function Python max() function Python User-define Functions Python Built-in Functions Anonymous/Lambda Function in Python

Python File Handling

Python File Handling Python Read CSV Python Write CSV Python Read Excel Python Write Excel Python Read Text File Python Write Text File Read JSON File in Python

Python Exception Handling

Python Exception Handling Python Errors and exceptions Python Assert

Python OOPs Concept

OOPs Concepts in Python Inheritance in Python Polymorphism in Python Python Encapsulation Python Constructor

Python Iterators

Iterators in Python Yield Statement In Python

Python Generators

Python Generator

Python Decorators

Python Decorator

Python Functions and Methods

Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods

Python Modules

Python Modules Python Datetime Module Python Calendar Module  

Python MySQL

Python MySQL Python MySQL Update Operation Python MySQL Delete Operation

Python MongoDB

Python MongoDB

Python Data Structure Implementation

Python Stack Python Queue Python Hash Table Python Graph

Python Advance Topics

Speech Recognition in Python Face Recognition in Python Python Rest API Python Command Line Arguments Python JSON Python Virtual Environment Type Casting in Python Collections in python Python Enumerate Python Debugger Python DefaultDict

Misc

Python PPTX Python Pickle Python Seaborn Python Coroutine Python EOL Python Infinity Python math.cos and math.acos function Python Project Ideas Based On Django Reverse a String in Python Reverse a Number in Python Python Word Tokenizer Python Trigonometric Functions Python try catch exception GUI Calculator in Python Implementing geometric shapes into the game in python Installing Packages in Python Python Try Except Python Sending Email Socket Programming in Python Python CGI Programming Python Data Structures Python abstract class Python Compiler Python K-Means Clustering List Comprehension in Python3 NSE Tools In Python Operator Module In Python Palindrome In Python Permutations in Python Pillow Python introduction and setup Python Functionalities of Pillow Module Python Argmin Python whois Python JSON Schema Python lock Return Statement In Python Reverse a sentence In Python tell() function in Python Why learn Python? Write Dictionary to CSV in Python Write a String in Python Binary Search Visualization using Pygame in Python Latest Project Ideas using Python 2022 Closest Pair of Points in Python ComboBox in Python Python vs R Python Ternary Operators Self in Python Python vs Java Python Modulo Python Packages Python Syntax Python Uses Python Logical Operators Python Multiprocessing Python History Difference between Input() and raw_input() functions in Python Conditional Statements in python Confusion Matrix Visualization Python Python Algorithms Python Modules List Difference between Python 2 and Python 3 Is Python Case Sensitive Method Overloading in Python Python Arithmetic Operators Design patterns in python Assignment Operators in Python Is Python Object Oriented Programming language Division in Python Python exit commands Continue And Pass Statements In Python Colors In Python Convert String Into Int In Python Convert String To Binary In Python Convert Uppercase To Lowercase In Python Convert XML To JSON In Python Converting Set To List In Python Covariance In Python CSV Module In Python Decision Tree In Python Difference Between Yield And Return In Python Dynamic Typing In Python Abstract design pattern in python Builder design pattern in python

How to

How to convert integer to float in Python How to reverse a string in Python How to take input in Python How to install Python in Windows How to install Python in Ubuntu How to install PIP in Python How to call a function in Python How to download Python How to comment multiple lines in Python How to create a file in Python How to create a list in Python How to declare array in Python How to clear screen in Python How to convert string to list in Python How to take multiple inputs in Python How to write a program in Python How to compare two strings in Python How to create a dictionary in Python How to create an array in Python How to update Python How to compare two lists in Python How to concatenate two strings in Python How to print pattern in Python How to check data type in python How to slice a list in python How to implement classifiers in Python How To Print Colored Text in Python How to develop a game in python How to print in same line in python How to create a class in python How to find square root in python How to import numy in python How to import pandas in python How to uninstall python How to upgrade PIP in python How to append a string in python How to open a file in python

Sorting

Python Sort List Sort Dictionary in Python Python sort() function Python Bubble Sort

Programs

Factorial Program in Python Prime Number Program in Python Fibonacci Series Program in Python Leap Year Program in Python Palindrome Program in Python Check Palindrome In Python Calculator Program in Python Armstrong Number Program in Python Python Program to add two numbers Anagram Program in Python Even Odd Program in Python GCD Program in Python Python Exit Program Python Program to check Leap Year Operator Overloading in Python Pointers in Python Python Not Equal Operator Raise Exception in Python Salary of Python Developers in India What is a Script in Python Singleton design pattern in python

Python SciPy Library

Introduction

SciPy, a logical library for Python is an open-source, BSD-authorized library for arithmetic, science, and design. The SciPy library relies upon NumPy, which gives advantageous and quick N-dimensional exhibit control. The fundamental justification for assembling the SciPy library is that it should work with NumPy exhibits. It gives numerous easy-to-understand and effective mathematical practices like routines for mathematical joining and improvement. This is a basic instructional exercise, which covers the essentials of SciPy and depicts how to manage its different modules.

SciPy vs NumPy

SciPy:

  1. SciPy is a logical calculation library that utilizes NumPy beneath. 
  2. SciPy represents Scientific Python. 
  3. It gives greater utility capacities to streamlining, details, and sign handling. 
  4. SciPy is open source so we can utilize it unreservedly. 
  5. SciPy was made by NumPy's maker Travis Oliphant.

Numpy:

  • Numpy is written in C and use for mathematical or numeric calculation.
  • It is faster than other Python Libraries
  • Numpy is the most useful library for Data Science to perform basic calculations.
  • Numpy contains nothing but array data type which performs the most basic operation like sorting, shaping, indexing, etc.
  • Numpy is used for numerical or mathematic computations.
  • Numpy is the most valuable library for Data Science for performing the essential operations. 
  • It is quicker and nimble than other Python Libraries 
  • Numpy contains only cluster information type which plays out the most essential activity like arranging, forming, ordering, and so on.

Installation of SciPy

If our system already has Python and PIP then the installation process of SciPy is very simple.

Installing SciPy in Windows via pip.

pip install scipy 

Before we begin learning SciPy Python, we need to realize fundamental usefulness just as various kinds of an array of NumPy.

After the installation of SciPy, import the SciPy module(s) which you want to apply in your applications and we can do this with 

from scipy import module statement:

The usual way to import SciPy modules and Numpy is:

from scipy import special   
import numpy as np

Example:

from scipy.special import cbrt
#Find cubic root of 27 & 64 using cbrt() function
cb = cbrt([27, 64])
#print value of cb
print(cb)

Output: 

array([3., 4.])

Checking version of SciPy

The __version__ attribute stores the string of the version.

Example:

import scipy


print(scipy.__version__)

SciPy Constants

The scipy.constants bundle gives different constants. We need to import the necessary consistency and use them according to the prerequisite. Allow us to perceive how these consistent factors are imported and utilized.

Example:

constant value of PI:


from scipy import constants


print(constants.pi)

Output:

3.141592653589793

Constant Units

A record of all units under the constants module can be seen by utilizing the dir() work. The dir() work returns the record of all units under the constant module.

Example

List all constants:

from scipy import constants


print(dir(constants))

Output:

It returns a list of constant units such as 

'Avogadro', 'Boltzmann', 'Btu', 'Btu_IT', 'Btu_th', 'C2F', 'C2K', 'ConstantWarning', 'F2C', 'F2K', 'G', 'Julian_year', 'K2C', 'K2F', 'N_A', 'Planck', 'R', 'Rydberg', 'Stefan_Boltzmann'

Categories of units

The units are located under certain categories:

  • Binary
  • Mass
  • Metric
  • Volume
  • Pressure
  • Energy
  • Speed
  • Power
  • Angle
  • Time
  • Length
  • Temperature
  • Force

Binary:

Specified Units returned in bytes

from scipy import constants


print(constants.kibi)   
print(constants.mebi)  
print(constants.gibi)  
print(constants.tebi)    
print(constants.pebi)    
print(constants.exbi)    
print(constants.zebi)   
print(constants.yobi)  

Output:

1024
1048576
1073741824
1099511627776
1125899906842624
1152921504606846976
1180591620717411303424
1208925819614629174706176

Mass:

The specified unit returned in kg

from scipy import constants
print(constants.gram)
print(constants.metric_ton)
print(constants.grain)
print(constants.lb)
print(constants.pound)
print(constants.oz)
print(constants.ounce)
print(constants.stone)
print(constants.long_ton)
print(constants.short_ton)
print(constants.troy_ounce)
print(constants.troy_pound)
print(constants.carat)
print(constants.atomic_mass)
print(constants.m_u)
print(constants.u)

Output:

0.001
1000.0
6.479891e-05
0.45359236999999997
0.45359236999999997
0.028349523124999998
0.028349523124999998
6.3502931799999995
1016.0469088
907.1847399999999
0.031103476799999998
0.37324172159999996
0.0002
1.66053904e-27
1.66053904e-27
1.66053904e-27

Metric (SI) :

The specified unit is returned in meter.

from scipy import constants

print(constants.yotta)
print(constants.zetta)
print(constants.exa)
print(constants.peta)
print(constants.tera)
print(constants.giga)
print(constants.mega)
print(constants.kilo)
print(constants.hecto)
print(constants.deka)
print(constants.deci)
print(constants.centi)
print(constants.milli)
print(constants.micro)
print(constants.nano)
print(constants.pico)
print(constants.femto)
print(constants.atto)
print(constants.zepto)

Output:

1e+24
1e+21
1e+18
1000000000000000.0
1000000000000.0
1000000000.0
1000000.0
1000.0
100.0
10.0
0.1
0.01
0.001
1e-06
1e-09
1e-12
1e-15
1e-18
1e-21

Volume:

The specified unit is returned in cubic meters.

from scipy import constants


print(constants.liter)
print(constants.litre)
print(constants.gallon)
print(constants.gallon_US)
print(constants.gallon_imp)
print(constants.fluid_ounce)
print(constants.fluid_ounce_US)
print(constants.fluid_ounce_imp)
print(constants.barrel)
print(constants.bbl)

Output:

0.001
0.001
0.0037854117839999997
0.0037854117839999997
0.00454609
2.9573529562499998e-05
2.9573529562499998e-05
2.84130625e-05
0.15898729492799998
0.15898729492799998

Pressure:

The specified unit is returned in pascals.

from scipy import constants


print(constants.atm)
print(constants.atmosphere)
print(constants.bar)
print(constants.torr)
print(constants.mmHg)
print(constants.psi)

Output:

101325.0
101325.0
100000.0
133.32236842105263
133.32236842105263
6894.757293168361
101325.0
101325.0
100000.0
133.32236842105263
133.32236842105263
6894.757293168361

Energy:

The specified unit is returned in joules.

from scipy import constants
print(constants.eV)
print(constants.electron_volt)
print(constants.calorie)
print(constants.calorie_th)
print(constants.calorie_IT)
print(constants.erg)
print(constants.Btu)
print(constants.Btu_IT)
print(constants.Btu_th)
print(constants.ton_TNT)

Output:

1.6021766208e-19
1.6021766208e-19
4.184
4.184
4.1868
1e-07
1055.05585262
1055.05585262
1054.3502644888888
4184000000.0

Speed:

The specified unit is returned in meters per second.

from scipy import constants


print(constants.kmh)
print(constants.mph)
print(constants.mach)
print(constants.speed_of_sound)
print(constants.knot)

Output:

0.2777777777777778
0.44703999999999994
340.5
340.5
0.5144444444444445

Power:

The specified unit is returned in watts.

from scipy import constants


print(constants.hp)
print(constants.horsepower)

Output:

745.6998715822701
745.6998715822701

Angle:

The specified unit returned in radians.

from scipy import constants


print(constants.degree)
print(constants.arcmin)
print(constants.arcminute)
print(constants.arcsec)
print(constants.arcsecond)

Output:

0.017453292519943295
0.0002908882086657216
0.0002908882086657216
4.84813681109536e-06
4.84813681109536e-06

Time:

The specified unit is returned in seconds.

from scipy import constants


print(constants.minute)
print(constants.hour)
print(constants.day)
print(constants.week)
print(constants.year)
print(constants.Julian_year)

Output:

60.0
3600.0
86400.0
604800.0
31536000.0
31557600.0

Length:

The specified unit is returned in meters.

from scipy import constants


print(constants.inch)
print(constants.foot)
print(constants.yard)
print(constants.mile)
print(constants.mil)
print(constants.pt)
print(constants.point)
print(constants.survey_foot)
print(constants.survey_mile)
print(constants.nautical_mile)
print(constants.fermi)
print(constants.angstrom)
print(constants.micron)
print(constants.au)
print(constants.astronomical_unit)
print(constants.light_year)
print(constants.parsec)

Output:

0.0254
0.30479999999999996
0.9143999999999999
1609.3439999999998
2.5399999999999997e-05
0.00035277777777777776
0.00035277777777777776
0.3048006096012192
1609.3472186944373
1852.0
1e-15
1e-10
1e-06
149597870691.0
149597870691.0
9460730472580800.0
3.0856775813057292e+16

Temperature:

The specified unit is returned in Kelvin.

from scipy import constants


print(constants.zero_Celsius)    
print(constants.degree_Fahrenheit) 

Output:

273.15
0.5555555555555556

Force:

The specified unit is returned in newton.

from scipy import constants


print(constants.dyn)
print(constants.dyne)
print(constants.lbf)
print(constants.pound_force)
print(constants.kgf)
print(constants.kilogram_force)

Output:

1e-05
1e-05
4.4482216152605
4.4482216152605
9.80665
9.80665

Image Processing with SciPy 

scipy.ndimage is a submodule of SciPy which is for the most part utilized for operating out an image-related activity ."n" dimensional image leads to ndimage.

With the help of SciPy Image Processing, we can do Geometrics transformation(pivot, crop, flip), filtering of images(sharp and de nosing), show image, image division, arrangement, and highlights extraction, and the MISC Package in SciPy contains prebuilt images which can be utilized to perform image control task.

Sub packages in SciPy:

SciPy includes various sub-packages for different scientific operations which are shown below:

NameDescription
ClusterClustering algorithms
ConstantsPhysical and mathematical constants
FftpackFast Fourier Transform routines
IntegrateIntegration and ordinary differential equation solvers
InterpolateInterpolation and smoothing splines
IoInput and Output
LinalgLinear algebra
NdimageN-dimensional image processing
OdrOrthogonal distance regression
OptimizeOptimization and root-finding routines
SignalSignal processing
SparseSparse matrices and associated routines
SpatialSpatial data structures and algorithms
SpecialSpecial functions
StatsStatistical distributions and functions

Conclusion

In this article, we have learned about the SciPy constant package and learned about categories of units in Constant sub-packages.



ADVERTISEMENT
ADVERTISEMENT