Python SciPy

The SciPy is the library of Python. It is the open source library used for scientific computing and mathematical problems. SciPy provides optimization, linear algebra, integration, interpolation.
It provides the user friendly numerical integrations.

Why use Scipy

SciPy contains the complex mathematical algorithm which is used for high level complex application,due to open source library its widely used in the world and develops applications, usually beneficial for data scientists and mathematicians.

Numpy vs SciPy

Biscally Numpy deals with basic operations like searching,indexing,sorting but SciPy deals with numerical data and deals with complex mathematical algorithms.

Numpy provides many functions to slove linear algebra and fourier transformation but SciPy is the full feature of both properties.

SciPy Packages

1 scipy.cluster vector quantization and the k-means algorithms
2 scipy.constants Used for the mathematical constants
3 scipy.fftpack Used for Fourier transform computation
4 scipy.integrate Integrating functions, given function object
5 scipy.interpolation Used for given data using linear interpolation.
6 scipy.linalg It is used for linear algebra routine.
7 Used for data input and output
8 scipy.ndimage Used for processing of multi dimensional images
9 scipy.odr It stands for Orthogonal distance regression.
10 scipy.optimize It is used for optimization.
11 scipy.signal Signal processing.
12 scipy.sparse 2-D sparse matrix package for numeric data.
13 scipy.spatial contained in the scipy.spatial.distance submodule. Delaunay Triangulation
14 scipy.special Special Function.
15 scipy.stats Statistics.
16 scipy.weave It is a tool for writing.

Installation of SciPy

Using pip command

pip install scipy


Using Anaconda

conda install -c anaconda scipy 

Installing In Mac

sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook py35-pandas py35-sympy py35-nose

Installing In Ubuntu

pip install scipy  

Demonstration of SciPy

Now we will takes some SciPy program with code explanation

File I/O Program:This program is used for reads and writing the data.


import numpy as abc    #import numpy function
from scipy import io   #import input output file from scipy
array = abc.zeros((5, 5) )  #cretes 5 by 5 dimension array
io.savemat('exmp.mat', {'ab': array})  #save data in exmp.mat
prog = io.loadmat('exmp.mat', struct_as_record=True)   #load data from exmp.mat
prog['ab']  #print output


array([[0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.]])

Cubic Root Function

from scipy.special import cbrt
#import cbrt function from scipy.special
a = cbrt([10, 20])
print(a)  #value print


[2.15443469 2.71441762]

Permutation and Combination

from scipy.special import comb
#import  combination function
a= comb(8, 6, exact = True, repetition=False)



Finding the determination of two matrix

from scipy import linalg #import linear algebraic function
import numpy as abc    #import numpy objects name is abc
#define 2 dimension matrix
TwoDmatrix = abc.array([ [7,9], [6,4] ])
#pass values to det() function
linalg.det( TwoDmatix )



Inverse of this matrix

from scipy import linalg #import linear algebraic function
import numpy as abc
#define 2 dimension matrix
TwoDmatrix = abc.array([ [7,9], [6,4] ])
#pass values to inv() function(inverse)
linalg.inv( TwoDmatrix )


array( [[-0.28571429,  0.71428571],
       [ 0.42857143, -0.57142857]] )
Subscribe Now