Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

🧮 NumPy Basics Roadmap

A Complete Beginner’s Guide to Mastering NumPy

Welcome to the NumPy Basics Roadmap — a self-paced and instructor-ready learning guide designed for anyone stepping into Data Science, Machine Learning, or Scientific Computing.

This guide focuses purely on the fundamentals — the foundation you must master before tackling advanced ML libraries like Pandas, Scikit-learn, or TensorFlow.


📘 Table of Contents

  1. Introduction
  2. Why Learn NumPy
  3. Setup and Getting Started
  4. Core Concepts
  5. Mini Projects
  6. Cheatsheet
  7. Learning Tips
  8. Resources
  9. About the Community

🌱 Introduction

NumPy (Numerical Python) is the heart of numerical computing in Python.
It’s what gives Python the ability to efficiently handle large datasets, perform matrix operations, and power most of the machine learning ecosystem.

NumPy introduces a special data structure called the ndarray — a fast, flexible, and memory-efficient way to represent and manipulate numerical data.


⚡ Why Learn NumPy

Benefit Description
🚀 Speed NumPy performs calculations up to 100x faster than pure Python lists
🧮 Mathematical Power Enables advanced operations like linear algebra, broadcasting, and randomization
🧠 ML Foundation Libraries like Pandas, TensorFlow, and Scikit-learn are all built on NumPy
📊 Data Handling Makes handling and transforming numerical data effortless

💻 Setup and Getting Started

Step 1: Install NumPy

pip install numpy jupyter

Step 2: Verify Installation

import numpy as np
print(np.__version__)

Step 3: Launch Jupyter Notebook

jupyter notebook

✅ You’re ready to start your NumPy journey!


🧩 Core Concepts

1️⃣ Array Creation

Common Array Constructors

Function Description Example
np.array() Create array from list or tuple np.array([1, 2, 3])
np.zeros() Array of zeros np.zeros((2,3))
np.ones() Array of ones np.ones((2,3))
np.full() Filled with constant np.full((3,3), 7)
np.arange() Range with steps np.arange(0, 10, 2)
np.linspace() Evenly spaced values np.linspace(0, 1, 5)
np.eye() Identity matrix np.eye(3)
np.random.rand() Random floats np.random.rand(2,3)
np.random.randint() Random integers np.random.randint(0,10,(2,3))

Examples:

import numpy as np

print(np.zeros((2, 3)))
print(np.arange(0, 10, 2))
print(np.linspace(0, 1, 5))
print(np.random.randint(0, 10, size=(2, 3)))

2️⃣ Array Properties

Attributes to Remember

arr = np.array([[1, 2, 3], [4, 5, 6]])

print("Shape:", arr.shape)
print("Dimensions:", arr.ndim)
print("Data type:", arr.dtype)
print("Size:", arr.size)
print("Item size:", arr.itemsize)

🧠 Arrays have a fixed type (dtype), making operations much faster than Python lists.


3️⃣ Indexing and Slicing

➤ 1D Arrays

arr = np.arange(10)
print(arr[2:7])
print(arr[:5])
print(arr[-3:])

➤ 2D Arrays

matrix = np.array([[10,20,30],[40,50,60],[70,80,90]])

print(matrix[0, 1])   # Access single element
print(matrix[1, :])   # Row 1
print(matrix[:, 2])   # Column 2
print(matrix[1:, 1:]) # Submatrix

➤ Fancy & Boolean Indexing

arr = np.array([10, 20, 30, 40, 50])
print(arr[[0, 3, 4]])      # Fancy indexing
print(arr[arr > 25])       # Boolean indexing

4️⃣ Array Operations

➤ Arithmetic

a = np.array([1,2,3])
b = np.array([10,20,30])

print(a + b)
print(a * b)
print(a / b)
print(a ** 2)

➤ Universal Functions (UFuncs)

print(np.sqrt(a))
print(np.exp(a))
print(np.log(a))

➤ Comparisons

print(a > 1)
print(b == 20)

5️⃣ Reshaping and Combining

➤ Reshaping

arr = np.arange(6)
matrix = arr.reshape(2, 3)

print(matrix)
print(matrix.T)  # Transpose

➤ Flattening

print(matrix.flatten())

➤ Stacking

a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])

print(np.vstack((a, b)))  # vertical stack
print(np.hstack((a, a)))  # horizontal stack

6️⃣ Math and Random Functions

➤ Aggregation

arr = np.array([[1, 2, 3], [4, 5, 6]])

print("Sum:", np.sum(arr))
print("Mean:", np.mean(arr))
print("Std:", np.std(arr))
print("Var:", np.var(arr))
print("Min:", np.min(arr))
print("Max:", np.max(arr))

➤ Axis Operations

print("Column means:", np.mean(arr, axis=0))
print("Row sums:", np.sum(arr, axis=1))

➤ Random Numbers

np.random.seed(42)

print(np.random.rand(2, 3))    # uniform distribution
print(np.random.randn(3))      # normal distribution
print(np.random.randint(1, 100, 5))  # random integers

💡 Mini Projects

🧩 1. Student Score Analysis

scores = np.random.randint(50, 100, (10, 5))

print("Scores:\n", scores)
print("Average per student:", np.mean(scores, axis=1))
print("Top student index:", np.argmax(np.mean(scores, axis=1)))

🧮 2. Temperature Tracker

temps = np.random.randint(18, 36, size=30)

print("Average temperature:", np.mean(temps))
print("Hottest day:", np.max(temps))
print("Coldest day:", np.min(temps))
print("Days above 30°C:", np.sum(temps > 30))

🧠 3. Random Data Simulation

data = np.random.randn(1000)
print("Mean:", np.mean(data))
print("Std deviation:", np.std(data))
print("Values > 1:", np.sum(data > 1))

📄 Cheatsheet

Operation Description Example
np.array() Create an array np.array([1,2,3])
np.arange() Range of values np.arange(0,10,2)
np.linspace() Evenly spaced values np.linspace(0,1,5)
np.zeros() Array of zeros np.zeros((3,3))
np.ones() Array of ones np.ones((2,4))
np.eye() Identity matrix np.eye(3)
.reshape() Change shape arr.reshape(2,3)
.T Transpose matrix.T
np.sum() Sum np.sum(arr)
np.mean() Mean np.mean(arr)
np.std() Standard deviation np.std(arr)
np.random.rand() Random floats np.random.rand(3,3)
np.random.randint() Random integers np.random.randint(1,10,(2,3))

🧭 Learning Tips

  • ✅ Always inspect your array’s .shape, .dtype, and .ndim.
  • 🧮 Prefer vectorized operations over Python loops — they’re much faster.
  • 🧠 Use np.random.seed() for reproducible results.
  • 💬 Print and visualize small arrays to understand transformations.
  • 📈 NumPy is the foundation for Pandas, Matplotlib, and ML frameworks — master it early!

📚 Resources


🤝 About the Community

This roadmap was created for the Machine Learning Community led by Dinah Nato — empowering learners to build strong foundations in Python, Data Science, and AI 🚀

💡 Keep learning, keep building, and keep sharing knowledge with others.



---

✅ You can copy the above Markdown **exactly as-is** into your `README.md` file — it’s complete, clean, and visually formatted for GitHub.  

Would you like me to make a **next-level enhanced version** (with badges, section dividers, emoji navigation bar, and GitHub-flavored collapsible sections for lessons)? It would make your repo look even more polished for your ML community.

About

A self_paced and instructor-ready learning guide for Numpy basics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors