NumPy Notes (Quick & Clear)
1. What is NumPy?
NumPy (Numerical Python) is a Python library used for numerical computing. It provides support for
arrays, mathematical operations, and linear algebra, and is much faster than Python lists.
Why NumPy? - Fast and efficient - Less memory usage - Easy mathematical operations - Base of ML,
Data Science, Pandas, SciPy
2. Installing & Importing NumPy
pip install numpy
import numpy as np
3. NumPy Array
A NumPy array stores elements of the same data type.
Creating an Array
arr = [Link]([1, 2, 3, 4])
print(arr)
Difference: List vs Array
List NumPy Array
Slow Fast
Different data types Same data type
Less math support Powerful math operations
1
4. Types of Arrays
1D Array
[Link]([1, 2, 3])
2D Array
[Link]([[1, 2], [3, 4]])
3D Array
[Link]([[[1,2],[3,4]], [[5,6],[7,8]]])
5. Array Attributes
arr = [Link]([[1,2,3],[4,5,6]])
- [Link] → number of dimensions - [Link] → rows & columns - [Link] → total
elements - [Link] → data type
6. Special Arrays
Zeros
[Link]((2,3))
Ones
[Link]((3,3))
Empty
[Link]((2,2))
2
Range
[Link](0, 10, 2)
Evenly Spaced
[Link](0, 10, 5)
7. Array Indexing & Slicing
arr = [Link]([10, 20, 30, 40])
- arr[0] → 10 - arr[1:3] → [20 30]
2D Indexing
arr[0,1]
8. Array Operations
Arithmetic Operations
a = [Link]([1,2,3])
b = [Link]([4,5,6])
a + b
a - b
a * b
a / b
Scalar Operations
a * 2
a + 5
3
9. Mathematical Functions
[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)
10. Reshaping Arrays
arr = [Link]([1,2,3,4,5,6])
[Link](2,3)
11. Copy vs View
a = [Link]() # deep copy
b = [Link]() # shallow copy
12. Stacking & Splitting
Stacking
[Link]((a,b))
[Link]((a,b))
Splitting
np.array_split(arr, 3)
13. Random Numbers
[Link](3,3)
[Link](1,10,5)
4
14. NumPy in Machine Learning
NumPy is used for: - Feature vectors - Matrix operations - Gradient calculations - Handling datasets
15. Important Exam Points ⭐
• NumPy arrays are faster than lists
• Uses contiguous memory
• Supports vectorization
• Used heavily in ML & Data Science
If you want: - Short exam notes - MCQs - Practice questions with answers - NumPy vs Pandas
comparison
Tell me 👍