SciPy is a Python-based ecosystem of open-source software for mathematics, science, and engineering.

SciPy is organized into sub-packages that cover different scientific computing domains. In this SciPy Tutorial, we shall learn all the modules and the routines/algorithms they provide.

SciPy contains following modules :

  • Cluster
  • Constants
  • FFTpack
  • Interpolate
  • Input and Output
  • Linalg
  • Ndimage
  • Optimize
  • Stats
  • CSGraph
  • Spatial
  • ODR
  • Special

SciPy Tutorial

In this SciPy tutorial, we will go through each of these modules with necessary examples to understand SciPy Basics.

SciPy Cluster Module

Clustering is the process of organizing objects into groups whose members are similar in some way.

K-Means

SciPy K-Means : Package scipy.cluster.vp provides kmeans() function to perform k-means on a set of observation vectors forming k clusters.

In this example, we shall generate a set of random 2-D points, centered around 3 centroids.

SciPy tutorial - SciPy K-Means Example SciPy tutorial - SciPy K-Means Example

Constants

SciPy contains physical and mathematical constants and units. Following list provides the broad categories and some of the examples.

  • Mathematical Constants
  • Physical Constants
  • SI Prefixes(kilo, mega, zeta)
  • Binary Prefixes(kibi, mebi, zebi)
  • Angle: degree, arcsec, etc., in radians
  • Time: minute, hour, week in seconds
  • Length: mile, yard, micron, etc., in meters
  • Pressure: atmosphere, torr, psi, etc., in Pascals
  • Area: hectare, acre in square meters
  • Volume
  • Speed
  • Temperature
  • Energy
  • Power
  • Force
  • Optics

FFTpack

FFT

scipy.fftpack provides fft function to calculate Discrete Fourier Transform on an array.

Output

IFFT

scipy.fftpack provides ifft function to calculate Inverse Discrete Fourier Transform on an array.

Output

Integrate

scipy.integrate contains many functions to compute definite integral.

In this example we will compute a definite integral using scipy.integrate.quad() function.

In the first line, we imported integrate module from scipy package. Then we created a lambda function x2 which is the square of input variable. We then passed this function to the quad() function with lower limit as 0 and upper limit as 4.

In the output of quad() function, the first value is the approximate value of the integral and the second value is an estimate of absolute error.

Interpolate

Interpolation is the process of finding the function, given input and output values. Interpolation is used regularly, where we have an experimental data containing inputs and outputs, and estimate the output for new inputs.

SciPy provides a variety of interpolate functions. In this example, we will take an equation y = f(x). Consider that we have performed a set of experiments and we have x values and their corresponding y values.

interp1d() returns a lambda function and is stored in f. Now you can estimate y values for new x values. We have estimated y values for x=0.5 and x=1.5.

Input and Output

Linalg

Ndimage

Optimize

Stats

CSGraph

Spatial

ODR

Special

Conclusion