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.
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
for loop! Just type A + B and NumPy does it instantly to the entire array all at once!mean), max, min, and standard deviation of your data.Go ahead and run the code to see NumPy crunch some numbers!
Related examples
Data Analysis with Pandas in Python
Learn Pandas for data analysis in Python! A beginner-friendly guide to DataFrames, filtering data, grouping, and handling messy missing data just like Excel.
Data Visualization with Matplotlib
Learn data visualization in Python with Matplotlib! A fun guide to creating line plots, scatter plots, and bar charts the recommended object-oriented way.