Introduction
Installation
To install NumPy:
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
ABOUT NUMPY
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
- import numpy as np
-
- arr = np.array( [[ 1, 2, 3],[ 4, 2, 5]] )
-
- print("Array is of type: ", type(arr))
- print("No. of dimensions: ", arr.ndim)
- print("Shape of array: ", arr.shape)
- print("Size of array: ", arr.size)
- print("Array stores elements of type: ", arr.dtype)
Output
About SciPy
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
- import numpy as np
- from scipy import linalg
-
- A= np.array([[1,2],[3,4]])
-
- B= np.array([[5],[6]])
-
- X= linalg.solve(A,B)
-
- print(X)
- print("\n Checking results, following vector should be all zeros")
- print(A.dot(X)-B)
About Matplotlib
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
- from matplotlib import pyplot as plt
-
- x = [5, 2, 9, 4, 7]
- y = [10, 5, 8, 4, 2]
-
- plt.bar(x,y)
- plt.show()
Output
About PyLab
PyLab is actually embedded inside matplotLib and provides a MATLAB-like experience for the user.
Example
- from numpy import *
- from pylab import *
-
- x = linspace(-3, 3, 30)
- y = x**2
-
- plot(x, y)
- 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