Python NumPy & Data Visualization Study Material
1. Introduction to NumPy
NumPy (Numerical Python) is a powerful library for numerical computations. It provides support for
n-dimensional arrays (ndarray),
vectorized operations, broadcasting, mathematical functions, and integrates well with scientific libraries.
Advantages of NumPy
• Fast execution due to C-based backend.
• Efficient memory usage via contiguous blocks.
• Vectorized operations eliminate Python loops.
• Supports complex mathematical, logical, and statistical operations.
2. ndarray (N-dimensional Array)
An ndarray is the core data structure of NumPy. It is a homogeneous, multidimensional array.
Creating ndarrays
You can create ndarrays using Python lists or NumPy functions:
• [Link]()
• [Link]()
• [Link]()
• [Link]()
• [Link]()
• [Link]()
3. Slicing ndarrays
NumPy supports slicing similar to Python lists, but more powerful:
• arr[start:end]
• arr[::-1] (reverse)
• For 2D: arr[rows, columns]
4. ndarray Operations
NumPy supports vectorized operations:
• Arithmetic operations: +, -, *, /
• Aggregate functions: mean(), sum(), std(), max()
• Matrix multiplication: dot(), matmul()
5. Broadcasting
Broadcasting allows operations between arrays of different shapes by expanding the smaller array
automatically.
Example:
Array + Scalar, Matrix + Row Vector.
6. Data Visualization in Python
Matplotlib is a fundamental plotting library in Python. It allows the creation of static, animated, and
interactive plots.
Plotting with Matplotlib
Basic steps:
1. import [Link] as plt
2. Create data
3. Call [Link](), [Link](), [Link](), etc.
4. Display using [Link]()
7. Univariate Graphs
Univariate means one variable.
• Histogram → distribution
• Boxplot → spread and outliers
• Line plot → trends
8. Bivariate Graphs
Bivariate means two variables.
• Scatter plot → relationship
• Line plot → x-y functions
• Bar chart → category vs value
9. Plotting Using Pandas
Pandas integrates with Matplotlib. DataFrame and Series objects have built-in plot() methods.
10. Improving Plot Aesthetics
• Add titles, labels, grid
• Increase figure size
• Use styles (e.g., seaborn)
• Add markers and linewidth
Conclusion
NumPy provides the foundation for numerical computing, while Matplotlib and Pandas offer powerful
visualization tools. Together, they form the essential stack for scientific computing, machine learning,
and data analysis in Python.