Chapter 4: NumPy Getting Started

NumPy – Getting Started (Really from Zero)

What is NumPy in one honest sentence?

NumPy is the library that lets Python handle lots of numbers very quickly and lets you do mathematics on entire collections of numbers at once — without writing slow for-loops.

It is the foundation of almost everything serious in:

  • Data analysis (pandas)
  • Machine learning & deep learning
  • Scientific computing
  • Image processing
  • Finance
  • Signal processing
  • Statistics
  • Simulations

Most important mindset change you need today:

Normal Python lists → think one number at a time NumPy arrays → think whole group of numbers at once

This single change makes your code:

  • 10–100× faster
  • Much shorter
  • Much easier to read (once you get used to it)

Step 1 – Let’s Install & Import (You Probably Already Have It)

In most modern environments (Jupyter, Colab, Anaconda, recent Python installations) NumPy is already there.

But if you need to install it:

Bash

Now in your Python code / notebook:

Python

Convention everyone follows: We almost always write np — not numpy, not num, not npy. Just accept it — it’s like pd for pandas, plt for matplotlib.

Python

Step 2 – Your Very First NumPy Array

Let’s create one right now.

Python

Compare with normal Python list:

Python

They look similar — but they are very different inside the computer.

Step 3 – First Magic: Math on the whole array (No loops!)

Let’s give everyone 5 bonus points.

Classic Python (slow when list is big):

Python

NumPy (fast & beautiful):

Python

No for loop. No list comprehension. NumPy did the +5 for every element automatically.

This is called vectorization — the #1 reason people fall in love with NumPy.

Let’s try more operations:

Python

Output examples:

text

Step 4 – Most Common Ways to Create Arrays (You’ll use these daily)

Python

Quick tip students always ask:

text

Step 5 – The 4 Things You Should Always Look At

Python

Real examples you will see soon:

text

Step 6 – Very Important Warning: Copying Arrays

Python

Correct ways to copy:

Python

Golden rule to remember:

text

Step 7 – Your First Tiny Realistic Example

Let’s say you have exam percentages and you want to:

  • Add 3 bonus points
  • Convert to scale 0–10
  • See who got > 85%
Python

Output:

text

No loops — clean, fast, readable.

Your First NumPy Survival Checklist

You should now be able to:

  • Import NumPy (import numpy as np)
  • Create arrays from lists
  • Use zeros, ones, arange, linspace
  • Generate random numbers
  • Do math on whole arrays (+ − × ÷ ** sqrt round …)
  • Check .shape, .dtype, .ndim, .size
  • Understand why we avoid for loops
  • Copy arrays correctly with .copy()

Where do you want to go next?

Pick whatever feels most useful right now:

  1. More ways to create arrays (realistic examples)
  2. Indexing & slicing (very important next step)
  3. Boolean masks — selecting data with conditions
  4. Broadcasting — the magic shape matching
  5. First statistics (mean, median, std, min, max…)
  6. Reshaping arrays (very common in data & ML)
  7. Common beginner mistakes and how to avoid them
  8. A small realistic mini-project together

Just tell me a number or say what you feel you need most — we continue exactly from here.

You’re doing great — let’s keep going! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *