An open API service indexing awesome lists of open source software.

https://github.com/sourabh-kumar04/numpy-basic

Numpy-Basic is a structured learning repo covering NumPy from basics to advanced. It includes arrays, indexing, reshaping, filtering, vector ops, angle functions, stats, and .npy file handling. Each concept is explained with code, examples, and Matplotlib visualizations in both light and dark modes. Ideal for students and data learners.
https://github.com/sourabh-kumar04/numpy-basic

data-analysis data-science data-visualization learning learning-resources machine-learning matplotlib numerical-computing numpy python python-library python-programming

Last synced: 6 months ago
JSON representation

Numpy-Basic is a structured learning repo covering NumPy from basics to advanced. It includes arrays, indexing, reshaping, filtering, vector ops, angle functions, stats, and .npy file handling. Each concept is explained with code, examples, and Matplotlib visualizations in both light and dark modes. Ideal for students and data learners.

Awesome Lists containing this project

README

          

# NumPy-Basic


NumPy Logo

A Comprehensive Guide to NumPy Fundamentals



[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Python](https://img.shields.io/badge/python-3.8%2B-brightgreen)](https://www.python.org/)
[![NumPy](https://img.shields.io/badge/NumPy-1.24%2B-orange)](https://numpy.org/)
[![Jupyter](https://img.shields.io/badge/Jupyter-Notebook-F37626.svg)](https://jupyter.org/)
[![GitHub stars](https://img.shields.io/github/stars/Sourabh-Kumar04/Numpy-Basic?style=social)](https://github.com/Sourabh-Kumar04/Numpy-Basic/stargazers)

From zero to hero: A structured learning path for mastering NumPy



[Getting Started](#-getting-started) โ€ข
[Learning Path](#-learning-path) โ€ข
[Examples](#-code-examples) โ€ข
[Contributing](#-how-to-contribute) โ€ข
[License](#-license)

## ๐Ÿ“‹ Overview

This repository provides a **comprehensive, step-by-step guide** to mastering NumPy, the fundamental package for scientific computing in Python. Each phase builds systematically on previous knowledge, with practical examples and clear explanations.

### ๐ŸŽฏ Who Is This For?

- ๐Ÿ”ฐ **Beginners** looking to build a solid foundation in NumPy
- ๐Ÿš€ **Intermediate users** wanting to deepen their understanding of advanced features
- ๐ŸŽ“ **Students** preparing for data science, machine learning, or AI coursework
- ๐Ÿ’ผ **Professionals** transitioning to roles requiring numerical computation skills

## โšก Quick Start

For those familiar with Python environments, get started immediately:

```bash
git clone https://github.com/Sourabh-Kumar04/Numpy-Basic.git
cd Numpy-Basic
python -m venv venv && source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
jupyter notebook
```

Begin with `Phase_1/01_phase_1.ipynb` and progress through each phase sequentially.

## ๐Ÿ“š Learning Path


NumPy Learning Path

### ๐Ÿ” Phase-by-Phase Progress

| Phase | Status | Topics | Key Concepts |
|-------|--------|--------|-------------|
| **๐Ÿงฉ Phase 1** | โœ… Complete | NumPy Fundamentals | Arrays vs Lists, Creating Arrays, Data Types, Basic Operations |
| **๐Ÿ“ Phase 2** | โœ… Complete | Data Manipulation | Indexing, Slicing, Sorting, Boolean Masks, Fancy Indexing |
| **๐Ÿ”„ Phase 3** | โœ… Complete | Array Transformation | Reshaping, Stacking, Splitting, Broadcasting Rules |
| **๐Ÿงฎ Phase 4** | ๐Ÿšง In Progress | Advanced Topics | Vector/Matrix Operations, Trigonometric Functions, Statistics, File Operations |

## ๐Ÿ“ Repository Structure

```
Numpy-Basic/
โ”œโ”€โ”€ LICENSE # Apache 2.0 License
โ”œโ”€โ”€ README.md # Project documentation
โ”œโ”€โ”€ main.py # Example runner script
โ”œโ”€โ”€ pyproject.toml # Project dependencies and configuration
โ”œโ”€โ”€ uv.lock # Dependency lock file (for uv users)
โ”œโ”€โ”€ Phase_1/
โ”‚ โ””โ”€โ”€ 01_phase_1.ipynb # NumPy Basics: Arrays, Creation, Types
โ”œโ”€โ”€ Phase_2/
โ”‚ โ””โ”€โ”€ 01_phase_2.ipynb # Data Access: Indexing, Slicing, Filtering
โ”œโ”€โ”€ Phase_3/
โ”‚ โ””โ”€โ”€ 01_phase_3.ipynb # Data Transformation: Reshaping, Stacking, Broadcasting
โ””โ”€โ”€ Phase_4/
โ”œโ”€โ”€ 01_phase_4.ipynb # Advanced: Math Operations, Statistics, Visualization
โ”œโ”€โ”€ array1.npy # Sample data file for practice
โ”œโ”€โ”€ array2.npy # Sample data file for practice
โ”œโ”€โ”€ array3.npy # Sample data file for practice
โ””โ”€โ”€ numpy_logo.npy # NumPy logo encoded as an array
```

## ๐Ÿ› ๏ธ Installation & Setup

### Prerequisites

- Python 3.8+ installed
- Git (for cloning the repository)
- Basic familiarity with Python programming

### Step-by-Step Setup

1. **Clone the repository**

```bash
git clone https://github.com/Sourabh-Kumar04/Numpy-Basic.git
cd Numpy-Basic
```

2. **Set up a virtual environment** (Choose your preferred method)

```bash
# Option 1: Standard venv
python -m venv venv
source venv/bin/activate # On macOS/Linux
# OR
venv\Scripts\activate # On Windows

# Option 2: Using uv (faster alternative)
uv venv
uv activate
```

3. **Install dependencies**

```bash
# Option 1: Using pip
pip install -r requirements.txt

# Option 2: Using uv with pyproject.toml
uv pip install -e .
```

4. **Launch Jupyter Notebook**

```bash
jupyter notebook
```

## ๐Ÿ“– What You'll Learn

### ๐Ÿงฉ Phase 1: NumPy Fundamentals


NumPy Array Illustration

- Why NumPy over standard Python lists?
- Performance benchmarks showing speed differences
- Memory efficiency comparisons
- Vectorized operations
- Creating arrays from different sources
- From Python lists
- Using built-in functions: `zeros()`, `ones()`, `arange()`, `linspace()`
- Random number generation
- Understanding array data types and properties

### ๐Ÿ“ Phase 2: Data Manipulation

- Accessing array elements
- Basic indexing vs fancy indexing
- Difference between views and copies
- Slicing multi-dimensional arrays
- Advanced selection with boolean masks
- Filtering data with conditions
- Combining multiple conditions
- Practical comparison between `np.where()` and boolean indexing
- Sorting arrays and finding unique values

### ๐Ÿ”„ Phase 3: Array Transformation

- Inspecting array properties
- Shape, size, dimensions, data type
- Reshaping arrays
- `reshape()`, `ravel()`, `flatten()`
- Adding/removing dimensions with `newaxis` and `squeeze()`
- Combining arrays
- Vertical stacking with `vstack()`
- Horizontal stacking with `hstack()`
- General stacking with `concatenate()`
- Broadcasting rules and compatibility
- When operations work between arrays of different shapes
- Common broadcasting errors and how to fix them

### ๐Ÿงฎ Phase 4: Applications & Advanced Features

- Vector, matrix, and tensor operations
- Dot products, cross products, matrix multiplication
- Linear algebra operations
- Comprehensive angle function reference
- Trigonometric functions (`sin`, `cos`, `tan`)
- Inverse trigonometric functions (`arcsin`, `arccos`, `arctan2`)
- Statistical functions for data analysis
- Measures of central tendency
- Measures of dispersion
- Percentiles and quantiles
- Working with NumPy's native file formats
- `.npy` for single arrays
- `.npz` for multiple arrays
- Data visualization with matplotlib

## ๐Ÿ“Š Code Examples

### Performance Comparison: Lists vs. NumPy Arrays

```python
import numpy as np
import time

# Python list operation
start = time.time()
python_list = list(range(1000000))
python_list = [x * 2 for x in python_list]
list_time = time.time() - start

# NumPy array operation
start = time.time()
numpy_array = np.arange(1000000)
numpy_array = numpy_array * 2
numpy_time = time.time() - start

print(f"Python list processing time: {list_time:.5f} seconds")
print(f"NumPy array processing time: {numpy_time:.5f} seconds")
print(f"NumPy is {list_time/numpy_time:.1f}x faster!")
```

Output

```
Python list processing time: 0.12345 seconds
NumPy array processing time: 0.00567 seconds
NumPy is 21.8x faster!
```

### Fancy Indexing & Masking

```python
import numpy as np

# Create sample data
data = np.random.randint(0, 100, size=(5, 5))
print("Original data:")
print(data)

# Boolean masking (values greater than 50)
mask = data > 50
filtered_data = data[mask]
print("\nValues greater than 50:")
print(filtered_data)

# Using np.where() for conditional values
result = np.where(data > 50, data * 2, data)
print("\nValues > 50 doubled, others unchanged:")
print(result)
```

### Visualization with Dark Mode

```python
import matplotlib.pyplot as plt
import numpy as np

# Set dark style
plt.style.use('dark_background')

# Generate data
x = np.linspace(0, 2 * np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create plot
plt.figure(figsize=(10, 6))
plt.plot(x, y1, label='sin(x)', color='cyan', linewidth=2)
plt.plot(x, y2, label='cos(x)', color='magenta', linewidth=2)
plt.title("Trigonometric Functions", fontsize=16)
plt.xlabel("x (radians)", fontsize=12)
plt.ylabel("Amplitude", fontsize=12)
plt.legend(fontsize=12)
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
```


Dark Mode Visualization Example

## ๐Ÿ“ˆ Statistical Functions Reference

| Function | Description | Example |
|----------|-------------|---------|
| `np.mean()` | Arithmetic mean | `np.mean(arr, axis=0)` |
| `np.median()` | Median value | `np.median(arr)` |
| `np.std()` | Standard deviation | `np.std(arr, ddof=1)` |
| `np.var()` | Variance | `np.var(arr)` |
| `np.min()` | Minimum value | `np.min(arr, axis=1)` |
| `np.max()` | Maximum value | `np.max(arr)` |
| `np.percentile()` | nth percentile | `np.percentile(arr, 75)` |
| `np.quantile()` | nth quantile | `np.quantile(arr, [0.25, 0.5, 0.75])` |
| `np.corrcoef()` | Correlation coefficient | `np.corrcoef(x, y)` |
| `np.cov()` | Covariance matrix | `np.cov(x, y)` |

## ๐Ÿ’พ Working with .npy Files

```python
import numpy as np

# Create sample array
array = np.random.normal(0, 1, size=(100, 100))

# Save to .npy file
np.save('sample_array.npy', array)

# Load from .npy file
loaded_array = np.load('sample_array.npy')

# Verify it's the same
print("Arrays are identical:", np.array_equal(array, loaded_array))
```

## ๐Ÿค” Common Questions & Answers

Why use NumPy instead of Python lists?
NumPy arrays are more efficient than Python lists for numerical operations because:


  • They store data in contiguous memory blocks

  • They leverage vectorized operations (SIMD instructions)

  • They offer specialized numerical functions optimized in C

  • They use less memory for the same amount of numerical data

What's the difference between a view and a copy?


  • A view is just a different way to access the same data - changes to the view affect the original array

  • A copy is a new array with the same values - changes to the copy don't affect the original

  • Basic slicing typically returns views, while advanced indexing returns copies

What are broadcasting rules?
Broadcasting allows NumPy to perform operations on arrays of different shapes. The rules are:


  • Arrays are compared from their trailing dimensions

  • Dimensions with size 1 are stretched to match the other array

  • Missing dimensions are treated as having size 1

  • If dimensions are compatible, broadcasting proceeds

## ๐Ÿ“š Additional Resources

- [Official NumPy Documentation](https://numpy.org/doc/stable/)
- [NumPy Cheat Sheet (PDF)](https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Numpy_Python_Cheat_Sheet.pdf)
- [From Python to NumPy](https://www.labri.fr/perso/nrougier/from-python-to-numpy/)
- [NumPy Tutorials](https://numpy.org/numpy-tutorials/)
- [100 NumPy Exercises](https://github.com/rougier/numpy-100)

## ๐Ÿง  How to Contribute

Contributions to improve this repository are welcome! Here's how you can help:

1. **Fork** the repository
2. **Create a branch** for your feature or fix
3. **Commit** your changes with descriptive messages
4. **Push** to your branch
5. Submit a **Pull Request**

### Commit Message Convention

```
git commit -m "โœจ Added Phase_3: Array reshaping and broadcasting examples"
```

| Emoji | Description |
|-------|-------------|
| โœจ | New features or content |
| ๐Ÿ› | Bug fixes |
| ๐Ÿ“ | Documentation updates |
| ๐Ÿ”ง | Configuration changes |
| ๐Ÿงน | Code cleanup |
| ๐ŸŽจ | Style improvements |

## ๐Ÿ’ฌ Community & Support

- **GitHub Discussions**: [Open a discussion](https://github.com/Sourabh-Kumar04/Numpy-Basic/discussions)
- **Issue Tracker**: [Report bugs or request features](https://github.com/Sourabh-Kumar04/Numpy-Basic/issues)

## ๐Ÿ“„ License

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ“Š Citation

If you use this repository in your research or educational materials, please cite it as:

```bibtex
@misc{kumar2025numpybasic,
author = {Kumar, Sourabh},
title = {NumPy-Basic: Comprehensive Guide to NumPy Fundamentals},
year = {2025},
publisher = {GitHub},
url = {https://github.com/Sourabh-Kumar04/Numpy-Basic},
howpublished = {\url{https://github.com/Sourabh-Kumar04/Numpy-Basic}},
}
```

## ๐ŸŒ Connect & Support

- **Author**: Sourabh Kumar
- **GitHub**: [@Sourabh-Kumar04](https://github.com/Sourabh-Kumar04)
- **LinkedIn**: [linkedin.com/in/sourabh-kumar04](https://linkedin.com/in/sourabh-kumar04)

---


If you find this repository helpful, please consider starring it! โญ๏ธ




Buy Me A Coffee


"NumPy doesn't just compute numbersโ€”it transforms how we think about data." ๐Ÿงฎ