100% found this document useful (1 vote)
33 views

Scipy Lib

Uploaded by

Arvind Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
33 views

Scipy Lib

Uploaded by

Arvind Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

WELCOME

TO
THE SESSION
ON

SciPy Library
By:
Mr. Pawan Kumar,
Assistant Professor, Deptt. Of Computer Science,
Shivaji College (University of Delhi).
CONTENT TO BE COVERED:
➢ Introduction to Python SciPy.
➢ NumPy Vs SciPy.
➢ Sub-Packages in SciPy
➢ Basic Functions in SciPy.
➢ Special Functions in SciPy.
➢ Integration Functions in SciPy.
➢ Fourier Transformations in SciPy.
➢ Linear Alzebra in SciPy.
➢ Interpolation Functions in SciPy.
What is Python SciPy

✓SciPy is Python Libracry Used to solve


scientific and mathematical probles.

✓It is built on NumPy.

✓Allows Manipulation and visualization.


NumPy Vs SciPy
✓NumPy and SciPy used for mathematical and
numerical analysis.

✓NumPy contains array data and basic


operations.

✓SciPy consists of all the numerical code.

✓SciPy contains fully-featured versions of


mathematical and scientific functions.
Sub-Packages in SciPy
S.N. Name Discription
1. scipy.cluster Cluster algorithms are used to vector quantization/ Kmeans.
2. scipy.constants It represents physical and mathematical constants.
3. scipy.fftpack It is used for Fourier transform.
4. scipy.integrate Integration routines
5. scipy.interpolation Interpolation
6. scipy.linalg It is used for linear algebra routine.
7. scipy.io It is used for data input and output.
8. scipy.ndimage It is used for the n-dimension image.
9. scipy.odr Orthogonal distance regression.
10. scipy.optimize It is used for optimization.
11. scipy.signal It is used in signal processing.
12. scipy.sparse Sparse matrices and associated routines.
13. scipy.spatial Spatial data structures and algorithms.
14. scipy.special Special Function.
Basic Functions

e.g. (code/syntax)
help(cluster) or help()
Scipy.info()
Scipy.source(cluster)
Special Functions

EXPONENTIAL FUNCTIONS TRIGONOMETRIC FUNCTIONS


 Example:  Examples
from scipy import special from scipy import special
e.g.-1
c=special.sindg(90)
a=special.exp10(3) print(c)
print(a) e.g.-2
d=special.cosdg(45)
print(d)
Integration Functions
GENERAL INTEGRATION DOUBLE INTEGRATION

 The quad function calculates the The dblquad function calculates


integral of a function which has one the double integral of a function
variable which has two variables
 Example  Example
from scipy import integrate from scipy import integrate
help(integrate.quad) help(integrate.quad)
i=scipy.integrate.quad(lambda e=lambda x,y: x*y**2
x:special.exp10(x),0,1)
f=lambda x: 1
print(i)
g=lambda x: -1
integrate.dblquad(e,0,2,f,g)

INTEGRATION DEALS WITH ADDING SLICES TO DETERMINE


THE WHOLE. INTEGRATION CAN BE USED TO FIND
DISPLACEMENT. AREA ETC
Fourier Transformations
✓A method that deals with expressing a
function as a sum of periodic components
and recovering the signal from those
components.

✓The fft and ifft functions can be used to


return the discrete Fourier transform of a
real or complex sequence.
Example of Fourier Transformations
from scipy.fftpack import
fft,ifft
import numpy as np
x=np.array([1,2,3,4])
y=fft(x)
print(y)

Output:
[10.-0.j -2.+2.j -2.-0.j -2.-2.j]
Linear Alzebra
✓SciPy is built on ATLAS LAPACK and
BLAS libraries and is extremely fast in
solving problems related to linear alzebra.

✓Inverse of a Matrix: inverse of a matrix A


is matrix B such that AB=I where I is the
indentity matrix consisting of ones down
the main diagonal denoted as B=A-I
Example of Linear Alzebra
from scipy import linalg
a=np.array([[1,2],[3,4]])
b=linalg.inv(a)
print(b)

Output:
[[-2. 1. ]
[ 1.5 -0.5]]
Interpolation Functions
✓Interpolation refers to constructing new
data points within a set of known data
points. The scipy.interpolate consists of
spline functions and classes. One-
dimensional and multidimentional
(univariate and multivariate) interpolation
classes etc.
Example of Interpolation Functions
import matplotlib.pyplot as plt
from scipy import interpolate
x=np.arange(5,20)
y=np.exp(x/3.0)
f=interpolate.interp1d(x,y)
x1=np.arange(6,12)
y1=f(x1) #use interpolation function returned by'interp1d'
plt.plot(x,y,'o',x1,y1,'--')
plt.show()

Output:

You might also like