Data ScienceBeginner

NumPy Array Operations in Python

Learn NumPy basics in Python! A fun and easy guide to super-fast arrays, matrices, and data science math without using slow for-loops.

Try it yourself

Run this code directly in your browser. Click "Open in full editor" to experiment further.

Loading...

Click Run to see output

Or press Ctrl + Enter

How it works

Welcome to NumPy (Numerical Python) — the absolute superpower behind all data science and AI in Python!

Why Use NumPy?

Standard Python lists are super flexible and great for everyday coding. But if you try to do heavy math on a list of a million numbers, Python gets really tired and slow.

NumPy gives us a special, hyper-optimized tool called an ndarray (N-Dimensional Array):

1. Super Strict: Unlike Python lists, every single item in a NumPy array must be the exact same type (like all integers or all decimals).

2. Super Fast: Because it's so strict, it can store the numbers packed tightly together in your computer's memory.

3. Written in C: Under the hood, NumPy runs lightning-fast C code to do the math for you!

Because of this, NumPy is often 10x to 100x faster than regular Python for loops!

Awesome Things We Can Do

  • Vectorization: Want to add 5 to every number in a list? Or multiply two giant lists together? You don't need a slow for loop! Just type A + B and NumPy does it instantly to the entire array all at once!
  • Data Analytics: It comes packed with built-in tools to instantly find the average (mean), max, min, and standard deviation of your data.
  • Go ahead and run the code to see NumPy crunch some numbers!

    Related examples

    Keywords: python numpy tutorial, numpy array operations, numpy matrix multiplication, python scientific computing, numpy broadcasting, data science python