Post

# Comparing SciPy, NumPy and Matplotlib

• 16.7k
• 0
• 2

## Installation

To install NumPy:

Refer to my article.

To install SciPy:

Use command: pip install scipy

If you get the below error:

Use command - python -m pip install --upgrade pip

To install MatplotLib

Use the command: python -mpip install -U matplotlib

Numerical python (N-dimensional array package)

Numpy adds python support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

For detailed information about Numpy, refer to my article on Numpy- Array.

Example
1. import numpy as np
2.
3. arr = np.array( [[ 123],[ 425]] )
4.
5. print("Array is of type: ", type(arr))                 # Printing type of arr object
6. print("No. of dimensions: ", arr.ndim)                 # Printing array dimensions (axes)
7. print("Shape of array: ", arr.shape)                   # Printing shape of array
8. print("Size of array: ", arr.size)                     # Printing size (total number of elements) of array
9. print("Array stores elements of type: ", arr.dtype)    # Printing type of elements in array
Output

Scientific python (Fundamental library for scientific computing)

Scipy is a collection of mathematical algorithms and convenience functions built on the Numpy extension of Python. It adds significant power to the interactive Python session by providing the user with high-level commands and classes for manipulating and visualizing data.

For detailed information, refer to my previous article on SciPy.

Example
1. import numpy as np
2. from scipy import linalg
3.
4. A= np.array([[1,2],[3,4]])
5.
6. B= np.array([[5],[6]])
7.
8. X= linalg.solve(A,B)
9.
10. print(X)
11. print("\n Checking results, following vector should be all zeros")
12. print(A.dot(X)-B)
OUTPUT

Comprehensive 2D Plotting

Matplotlib consists of several plots like line, bar, scatter, histogram, etc. Plots help to understand trends, patterns, and to make correlations.

For detailed information, refer to my article about MatplotLib.

Example
1. from matplotlib import pyplot as plt
2.
3. x = [52947]
4. y = [105842]
5.
6. plt.bar(x,y)
7. plt.show()
Output

PyLab is actually embedded inside matplotLib and provides a MATLAB-like experience for the user.

Example
1. from numpy import *
2. from pylab import *
3.
4. x = linspace(-3330)
5. y = x**2
6.
7. plot(x, y)
8. show()
Output

## Conclusion

• NumPy- Numerical python (N-dimensional array package)
• SciPy- Scientific python (Fundamental library for scientific computing)
• Matplotlib- Comprehensive 2D Plotting
NumPy is a general-purpose array-processing package.
• SciPy and NumPy are scientific projects whose aim is efficient and fast numeric computing to Python.
• Most new Data Science features are available in SciPy rather than NumPy.
• SciPy is a fully-featured version of Linear Algebra while NumPy contains only a few features.
• NumPy is faster than other Python Libraries
Matplotlib is the name of the python plotting library.
• Pyplot is an interactive API for matplotlib, like this: import matplotlib.pyplot as plt.
• Pylab is the same thing as pyplot, but with extra.
• Pylab = pyplot + numPy

Recommended Free Ebook
Similar Articles