SciPy stands for Scientific Python. Scipy is a Scientific library for python is an open source, The Scipy library functions depends on Numpy. It is under best on BSD license. SciPy was created by NumPy’s created by Travis Olliphant.

Home Page - Basic Engineer
Home Page – Basic Engineer

SciPy Sub Packages

  • Scipy.io
  • scipy.special
  • scipy.linalg
  • scipy.interpolate
  • scipy.optimize
  • scipt.stats
  • scipt.integrate
  • scipyt.fftpack
  • scipy.signal
  • scipy.ndimage

Scipy.io

The SciPy.io package supports a web range of functions to work with a different format of files. sio means is Scipy input output.

These are some formats are following :-

  1. Matlab
  2. IDL
  3. Matrix Market
  4. Wave
  5. Arff
  6. Netcdf

Example of Scipy.io

 import numpy as np
 from scipy import io as sio
 array = np.ones((5, 5))
 why.savemat('what.mat', {'ar': array}) 
 data = why.loadmat(‘what.mat', struct_as_record=True)
 data['ar']

Output

array([[ 1.,1., 1., 1., 1.],
           [ 1., 1., 1., 1., 1.],
           [ 1.,1., 1., 1., 1.],
           [ 1.,1., 1., 1., 1.],
           [ 1., 1., 1., 1., 1.]])

scipy.special

This package contains numerous functions of mathematical. SciPy special function includes Cubic Root, Exponential, Permutation and Combinations, Gamma, Bessel, hypergeometric, Kelvin, beta, parabolic cylinder etc.

Cubic Root Function

Cubic Root function defines the cube root of values.

Syntax

scipy.special.cbrt(x)

Example of Cubic Root Function

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

Output:

([2., 5.])

Exponential Function

Example of Exponential Function

from scipy.special import exp10
#define exp10 function and pass value in its
exp = exp10([1,10])
print(exp)

Output

 [1.e+01 1.e+10]

Permutations & Combinations

Permutations

Syntax

scipy.special.perm(x,y)

Example of Permutation

from scipy.special import perm
#find permutation of 5, 3 using perm (N, k) function
per = perm(5, 3, exact = True)
print(per)

Output: 60

Combinations

Syntax

scipy.special.comb(x,y)

Example of Combination

from scipy.special import comb
#find combinations of 5, 3 values using comb(N, k)
com = comb(5, 3, exact = False, repetition=True)
print(com)

Output: 10

Scipy Stats

The scipy.stats contains a large number of statistics, probability distributions functions is knows as Scipy stats.

Syntax

scipy.stats.lognorm.method_name(data,loc,size,moments,scale)

Scipy ndimage

scipy.ndimage is a submodule of SciPy. ndimage means “n” dimensional image. SciPy Image Processing provides Geometrics transformation, image filter , display image, image segmentation, classification and features extraction.

Example of Scipy ndimage

from scipy import misc
from matplotlib import pyplot as plt
import numpy as np
#get face image of panda from misc package
panda = misc.face()
#plot or show image of face
plt.imshow( apple )
plt.show()
Scipy
python

Scipy optimize

Scipy Optimize provides a useful algorithm for minimization of curve fitting, multidimensional or scalar and root fitting is knows as Scipy Optimize.

Example of Scipy Optimize

%matplotlib inline
import matplotlib.pyplot as plt
from scipy import optimize
import numpy as np

def function(d):
       return   a*4 + 10 * np.sin(d)
plt.plot(a, function(a))
plt.show()
#use BFGS algorithm for optimization
optimize.fmin_bfgs(function, 0) 

 Scipy fftpack

  • It is stands for Fast Fourier Transformation.
  • FFT is apply to a multidimensional array.
  • The Frequency defines the number of signal or wavelength in particular time period.

Example of Scipy fffpack

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np 

#Frequency in terms of Hertz
fre  = 15 
#Sample rate
fre_samp = 55
t = np.linspace(0, 2, 2 * fre_samp, endpoint = False )
a = np.sin(fre  * 2 * np.pi * t)
figure, axis = plt.subplots()
axis.plot(t, a)
axis.set_xlabel ('Time (s)')
axis.set_ylabel ('Signal amplitude')
plt.show()

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about Scipy Library Function please Wikipedia Click here.

Stay Connected Stay Safe, Thank you.


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *