Introduction to NumPy

NumPy is a Python library for fast numerical computing on arrays — it gives you a powerful n-dimensional array object and a huge collection of vectorized math functions that run in optimized C code.

Learn Introduction to NumPy in our free NumPy course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free Numpy course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

In this first lesson you'll learn what NumPy is, why it's so much faster than plain Python lists, and how to install and import it ready for the rest of the course.

NumPy (short for Numerical Python ) is the core library for numerical computing in Python. Its star feature is the ndarray — a grid of values, all of the same type, that can be one-dimensional (a list of numbers), two-dimensional (a table or matrix), or have many more dimensions.

Almost every data tool in Python — pandas, scikit-learn, TensorFlow, OpenCV, Matplotlib — is built on top of NumPy arrays. Learning NumPy unlocks the entire scientific Python ecosystem.

Expected output: the array [1 2 3 4 5] , its type numpy.ndarray , then [ 2 4 6 8 10] and [101 102 103 104 105] .

A Python list can hold any mix of types, which makes it flexible but slow. A NumPy array holds one type in contiguous memory, so operations run in compiled C — often 10–100× faster on large data.

Expected output: both print the same values, but the NumPy version is one line and far faster on big arrays: [12. 24. 36. 48.] .

Install NumPy once from your terminal using pip:

Then import it at the top of every script. The whole community uses the alias np :

Expected output: the 2×3 grid, Shape: (2, 3) , and Sum: 21 .

Replace each ___ so the program creates an array and triples every value.

Expected output: [15 30 45] . (Answers: numpy , array , 3 .)

❌ ModuleNotFoundError: No module named 'numpy'

✅ Fix: run pip install numpy (or pip3 install numpy ).

You forgot the import, or imported under a different name.

✅ Fix: add import numpy as np at the top of the file.

Convert a list of Celsius temperatures to Fahrenheit using a single vectorized expression.

Lesson 1 complete — you've met NumPy!

You now know what NumPy is, why its arrays are faster than lists, and how to install and import it. You even ran your first vectorized math without a single loop.

🚀 Up next: The ndarray — take a close look at the core object that makes everything possible.

Practice quiz

What does NumPy stand for?

  • Numerical Python
  • Number Pyramid
  • Numeric PyTorch
  • New Python

Answer: Numerical Python. NumPy is short for Numerical Python, the core library for numerical computing.

What is the universal community alias for importing NumPy?

  • nump
  • np
  • numpy
  • npy

Answer: np. Everyone writes 'import numpy as np', so the np alias is expected everywhere.

What is NumPy's core array object called?

  • list
  • matrix
  • ndarray
  • dataframe

Answer: ndarray. The ndarray (n-dimensional array) is NumPy's star data structure.

Which command installs NumPy from the terminal?

  • npm install numpy
  • import numpy
  • python numpy
  • pip install numpy

Answer: pip install numpy. You install NumPy once with 'pip install numpy'.

Why is NumPy faster than plain Python lists for math?

  • It uses more RAM
  • It uses threads only
  • It runs vectorized math in compiled C on contiguous memory
  • It avoids importing

Answer: It runs vectorized math in compiled C on contiguous memory. Contiguous storage plus optimized C makes element-wise math 10-100x faster.

Given arr = np.array([1, 2, 3, 4, 5]), what does arr * 2 produce?

Vectorized multiplication doubles every element: [2 4 6 8 10].

What does grid.shape return for np.array([[1,2,3],[4,5,6]])?

  • (2, 3)
  • (3, 2)
  • (6,)
  • 6

Answer: (2, 3). Shape (2, 3) means 2 rows and 3 columns.

Applying one expression to every element with no loop is called what?

  • Looping
  • Recursion
  • Vectorization
  • Iteration

Answer: Vectorization. Vectorization applies an operation to the whole array at once at C speed.

Which error message means NumPy is not installed?

  • SyntaxError
  • ValueError
  • TypeError
  • ModuleNotFoundError: No module named 'numpy'

Answer: ModuleNotFoundError: No module named 'numpy'. A missing install raises ModuleNotFoundError; fix it with pip install numpy.

What does grid.sum() return for np.array([[1,2,3],[4,5,6]])?

  • 6
  • 15
  • 21

Answer: 21. Summing every element 1+2+3+4+5+6 gives 21.