# Understanding Scientific Python

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. Scipy source code. Image courtesy of Shishirdasika.

## Constants in Scipy

Scipy provides several built-in constants. For instance, to access “pi”, you can say:
scipy.constants.pi

Scipy provides several Mathematical as well as Physical constants. For instance, pi, golden ratio, speed_of_light, Avogadro, electron_mass, etc.

## Mathematical Transformations

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
print y

y_inverse = ifft(y) # Scipy also supports IFFT
print y_inverse

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
print y

## Numerical Integration

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
print i

## Image Processing

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)
plt.imshow(blurred_image)
plt.show()

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.

##### Comments are closed.

Magoosh blog comment policy: To create the best experience for our readers, we will only approve comments that are relevant to the article, general enough to be helpful to other students, concise, and well-written! 😄 Due to the high volume of comments across all of our blogs, we cannot promise that all comments will receive responses from our instructors.

We highly encourage students to help each other out and respond to other students' comments if you can!

If you are a Premium Magoosh student and would like more personalized service from our instructors, you can use the Help tab on the Magoosh dashboard. Thanks!