Skip to content

bremsstrahlung-57/numpy_for_noobs

Repository files navigation

NumPy For Noobs

Hey there! 👋 Welcome to your friendly guide to NumPy - the superhero of numerical computing in Python! Whether you're just starting out with data science or looking to brush up on your NumPy skills, you're in the right place.

I created this guide while learning NumPy myself, so trust me - it's written with beginners in mind! Inside, you'll find clear examples and explanations of the most commonly used NumPy functions in Machine Learning, including:

  • 🎲 Creating and playing with arrays (the building blocks of NumPy)
  • 🔄 Reshaping and manipulating data like a pro
  • 🎯 Picking out exactly the data you need (indexing & slicing)
  • 🧮 Doing cool math stuff with arrays
  • 📊 Statistical operations made easy
  • ✅ Checking and filtering your data
  • 🛠️ Essential tools for Machine Learning

📌 Future Plans:

  • Optimizing Performance
  • Real-World Applications

NOTE:

  • This guide covers the most important parts of NumPy, but there's always more to explore in the NumPy Docs
  • Some examples were created with help from AI tools (because why not use all available resources!)
  • Some functions are explained in other files later in the repository. Sorry about that, will fix it.

Let's dive in and make NumPy fun!

All the best


Contents

This covers the following topics:

  1. Creating and Initializing Arrays
  • np.array() → Create arrays from lists/tuples
  • np.zeros() → Create an array filled with zeros
  • np.ones() → Create an array filled with ones
  • np.full() → Create an array with a constant value
  • np.eye() → Identity matrix (useful in linear algebra)
  • np.linspace() → Generate evenly spaced numbers
  • np.arange() → Generate numbers with a step size
  • np.random.rand() → Random samples from uniform distribution (0,1)
  • np.random.randn() → Random samples from normal distribution
  • np.random.randint() → Random integers in a given range
  1. Data Manipulation
  • np.copy() → Create a duplicate of an array
  • np.reshape() → Reshape arrays (e.g., from 1D to 2D)
  • np.flatten() → Convert multi-dimensional arrays to 1D
  • np.ravel() → Flatten an array (like flatten(), but returns a view when possible)
  • np.transpose() → Transpose an array
  • np.hstack() → Horizontally stack arrays
  • np.vstack() → Vertically stack arrays
  • np.concatenate() → Concatenate multiple arrays
  • np.split() → Split an array into subarrays
  1. Indexing and Slicing
  • np.where() → Conditional indexing (e.g., np.where(arr > 0, 1, 0))
  • np.take() → Select elements at specific indices
  • np.argsort() → Get indices that would sort an array
  • np.argmax() → Get index of max value
  • np.argmin() → Get index of min value
  1. Mathematical Operations
  • np.add(), np.subtract(), np.multiply(), np.divide() → Element-wise operations
  • np.power() → Element-wise exponentiation
  • np.exp() → Exponential function
  • np.log() → Natural logarithm
  • np.log10() → Base-10 logarithm
  • np.sqrt() → Square root
  • np.sin(), np.cos(), np.tan() → Trigonometric functions
  • np.dot() → Dot product (used in linear algebra)
  • np.matmul() → Matrix multiplication
  • np.linalg.inv() → Matrix inverse
  • np.linalg.det() → Determinant of a matrix
  • np.linalg.eig()→ Eigenvalues and eigenvectors
  • np.linalg.svd() → Singular Value Decomposition (SVD)
  1. Statistical and Aggregation Functions
  • np.sum() → Sum of elements
  • np.mean() → Mean of elements
  • np.median() → Median of elements
  • np.var() → Variance
  • np.std() → Standard deviation
  • np.corrcoef() → Pearson correlation coefficient
  • np.percentile() → Compute percentile of data
  • np.histogram() → Compute histogram of an array
  1. Boolean and Comparison Operations
  • np.all() → Check if all elements satisfy a condition
  • np.any() → Check if any element satisfies a condition
  • np.isfinite() → Check for finite values
  • np.isinf() → Check for infinite values
  • np.isnan() → Check for NaNs
  1. Utility Functions for ML
  • np.clip() → Clip values within a specified range
  • np.unique() → Find unique values in an array
  • np.bincount() → Count occurrences of values
  • np.meshgrid() → Generate coordinate grids (useful in visualization)
  1. Random Number
  • np.random.rand() → Uniform distribution (0 to 1)
  • np.random.randn() → Standard normal distribution (mean=0, std=1)
  • np.random.randint() → Random integers
  • np.random.choice() → Sampling from an array
  • np.random.seed(42) → Why setting a seed is important for ML
  • np.random.permutation() → Shuffling arrays (important for dataset splitting)
  • np.random.shuffle() → In-place shuffling
  • np.random.normal() → Generating synthetic data
  • np.random.uniform() → Anoth

If you want to follow a path for learning through this repo, the following would be best:

numpy_for_noobs/
│── 📜 README.md                      # Project introduction & guide
│
├── 🔰 basics/                         # Fundamental NumPy concepts
│   ├── 📂 01_creating_arrays.ipynb      # Creating and initializing arrays
│   ├── 📂 02_order_in_numpy.md         # Memory order (C vs. F order)
│   ├── 📂 03_indexing_slicing.ipynb    # Accessing elements in arrays
│   ├── 📂 04_mathematical_operations.ipynb  # Basic math operations
│   ├── 📂 05_boolean_comparison.ipynb  # Boolean and comparison operations
│
├── ⚡ operations/                      # Array manipulations & computations
│   ├── 📂 06_vector_and_matrix.ipynb   # Vector and matrix operations
│   ├── 📂 07_data_manipulation.ipynb   # Transforming and reshaping arrays
│   ├── 📂 08_statistical_functions.ipynb  # Aggregation & statistical functions
│   ├── 📂 09_random_numbers.ipynb      # Generating random numbers
│
├── 🚀 advanced/                        # Advanced NumPy techniques
│   ├── 📂 10_linear_algebra.ipynb      # Linear algebra operations
│   ├── 📂 11_utility_functions_ml.ipynb  # NumPy utilities for ML
│   ├── 📂 12_optimizing_performance.ipynb(to be added?)  # Performance optimization
│
└── 🌍 extra/                           # Additional resources
    ├── 📂 13_C-Order_and_F-Order.md    # Explanation of memory layouts
    ├── 📂 14_real_world_applications.ipynb(to be added?)  # NumPy in real-world ML tasks

Getting Started

  1. Open the notebook in Google Colab.
  2. Run the code cells sequentially to understand the concepts and see the output.
  3. Experiment with the code by modifying values and observing the results.

Requirements

  • Python 3.x
  • NumPy library

Author

Sagar Sharma

Releases

No releases published

Packages

No packages published