Basics of NumPy Library
A Beginner's Guide to Numerical
Python
By Aman Sharma
What is NumPy?
• • NumPy (Numerical Python) is a library in
Python for numerical computing.
• • Key Features:
• - Multi-dimensional arrays (ndarray)
• - Mathematical functions and linear algebra
• - Broadcasting and vectorized operations
• • Why Use NumPy?
• - Faster and more memory-efficient than
standard Python lists.
Key Features of NumPy
• • Core Data Structure: ndarray
(Homogeneous, multi-dimensional arrays)
• • Benefits:
• - Element-wise operations
• - Efficient indexing and slicing
• - Mathematical computations (mean,
median, sum, etc.)
• • Example Code:
• import numpy as np
Creating Arrays
• • 1D Array:
• np.array([1, 2, 3])
• • 2D Array:
• np.array([[1, 2], [3, 4]])
• • Special Arrays:
• - Zeros: np.zeros((2, 3))
• - Ones: np.ones((3, 3))
Array Operations
• • Arithmetic Operations:
• arr = np.array([1, 2, 3])
• print(arr + 5) # [6, 7, 8]
• • Statistical Operations:
• arr = np.array([1, 2, 3, 4])
• print(arr.mean(), arr.sum())
• • Matrix Multiplication:
Conclusion & Applications
• • Why Learn NumPy?
• - Foundation for libraries like Pandas, SciPy,
and TensorFlow
• - Essential for data science, machine learning,
and numerical simulations
• • Applications:
• - Data Analysis
• - Machine Learning