Scientific Python, popularly known as Scipy, is a powerful mathematics and number processing library in Python. Here are some of the key points to note about Scipy:
- Scipy is open source and comes under BSD-licensed (permissive free software license).
- Scipy depends heavily on Numpy, which is another Python library for large data processing.
- Scipy provides several built-in functions for mathematical optimization, numerical integration, etc.
You can download and install scipy by accessing their official website.
Let us understand some basic functionality that is made available as a part of Scipy library.
Constants in Scipy
Scipy provides several built-in constants. For instance, to access “pi”, you can say:
Scipy provides several Mathematical as well as Physical constants. For instance, pi, golden ratio, speed_of_light, Avogadro, electron_mass, etc.
Scipy provides many commonly used built-in transformations. For instance, Discrete Cosine Transform (DCT) and Fast Fourier Transform. Let us see some examples:
from scipy.fftpack import fft, ifft # importing the libraries
x = np.array([3.0, 1.2, -1.3, 2.0, -2.7]) # test array
y = fft(x) # y stores FFT of x
y_inverse = ifft(y) # Scipy also supports IFFT
from scipy.fftpack import dct # importing the libraries
x = np.array([4., 3., 5., 10., 5., 3.]) # test array
y = dct() # y stores DCT of x
Scipy provides several built-in, easy-to-use numerical integration methods that help in fast computation.
import scipy.integrate # importing the libraries
from numpy import exp
f = lambda x: 3 * (x ** 2) # f is the function to be integrated
i = scipy.integrate.quad(f, 0, 1) # using scipy integration
Image Processing is frequently used in Computer Vision. Computer Vision Researchers use several image processing techniques in order to perform various transformations in the image. These transformations help in reducing unnecessary data in the image, mapping the image in a different domain, etc. The example below demonstrates how scipy can be used to blur a simple image by applying a Gaussian filter on the image:
from scipy import misc
import matplotlib.pyplot as plt
image = misc.face()
blurred_image = ndimage.gaussian_filter(image, sigma=3)
To conclude, Scipy is quite a powerful library and is widely used as an equivalent of MATLAB in Python programming. Scipy is extensively used in data cleaning and preprocessing and any Data Science/Machine Learning enthusiasts should definitely consider mastering Scipy in order to perform the processing tasks faster.