SciPy (Python Library)
Prepared By:
Jenish Patel
Jesal Zala
Kirtan Shah
Sanyukta Gautam
SciPy
SciPy is an Open Source Python-based library, which is used in mathematics, scientific computing,
Engineering, and technical computing.
● SciPy contains varieties of sub packages which help to solve the most common issue related to
Scientific Computation.
● Scipy is easy to use and understand.
● It can operate on an array of NumPy library.
Subpackage Description
SciPy Organization
cluster Clustering algorithms
constants Physical and mathematical constants
fftpack Fast Fourier Transform routines
SciPy is organized into subpackages covering different
scientific computing domains. These are summarized in integrate Integration and ordinary differential equation
solvers
the table:
interpolate Interpolation and smoothing splines
io Input and Output
Scipy sub-packages need to be imported separately, for linalg Linear algebra
example:
ndimage N-dimensional image processing
>>> from scipy import linalg, optimize odr Orthogonal distance regression
optimize Optimization and root-finding routines
signal Signal processing
sparse Sparse matrices and associated routines
spatial Spatial data structures and algorithms
special Special functions
stats Statistical distributions and functions
Sparse Matrix with SciPy
Construction of Matrix in COO Format.
Duplicate entries are summed when converting to CSR or CSC.
https://docs.scipy.org/doc/scipy/reference/tutorial/general.html
https://docs.scipy.org/doc/scipy/reference/tutorial/basic.html
https://docs.scipy.org/doc/scipy/reference/tutorial/index.html
https://hal.inria.fr/hal-01206546/file/ScipyLectures-simple.pdf
Spatial data structures and algorithms (scipy.spatial)
scipy.spatial can compute triangulations, Voronoi diagrams, and convex hulls of a set of points, by leveraging the Qhull library.
Convex hulls
Convex hull is the smallest convex object containing all points in a given point set.
These can be computed via the Qhull wrappers in scipy.spatial as follows:
>>> from scipy.spatial import ConvexHull
>>> points = np.random.rand(30,2) # 30 random points in 2-D
>>> hull = ConvexHull(points)
>>> import matplotlib.pyplot as plt
>>> plt.plot(points[:,0],points[:,1],'o')
[<matplotlib.lines.Line2D object at 0x13E5F630>]
>>> for simplex in hull.simplices:
... plt.plot(points[simplex,0],points[simplex,1],'k-')
>>> plt.show()
Voronoi diagrams
>>> from scipy.spatial import KDTree
>>> points = np.array([[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],
... [2,0],[2,1],[2,2]])
>>> tree = KDTree(points)
>>> tree.query([0.1,0.1])
(0.14142135623730953, 0)
>>> x=np.linspace(-0.5,2.5,31) # np.linspace(start, stop, num=50)
>>>y=np.linspace(-0.5,2.5,33)
>>> xx,yy = np.meshgrid(x,y) #np.meshgrid(*xi, **kwargs) , Return coordinate matrices from coordinate vectors,Make N-D coordinate arrays for vectorized evaluations of, N-D scalar/vector fields over N-D grids,
given one-dimensional coordinate arrays x1, x2,..., xn.
>>> xy = np.c_[xx.ravel(),yy.ravel()]
>> import matplotlib.pyplot as plt
>>> plt.pcolor(x,y,tree.query(xy)[1].reshape(33,31))
<matplotlib.collections.PolyCollection object at 0x2E3CBCF0>
>>> plt.plot(points[:,0],points[:,1],'ko')
[<matplotlib.lines.Line2D object at 0x2E657890>]
>>> plt.show()