FoundationsCore· 30 min read

NumPy Arrays vs Python Lists

A NumPy array is like a Python list, but built for fast maths on lots of numbers at once.

What you will learn

  • Create a NumPy array
  • Explain why arrays beat lists for numbers
  • Read an array’s shape

Why not just use a list?

You already know Python lists. They are great, but slow and clumsy when you have thousands of numbers to crunch. NumPy (short for “Numerical Python” — a free add-on library for fast number work) gives you the array — a list-like container built only for numbers, and it is much faster.

NumPy is the foundation: Pandas, Matplotlib and scikit-learn are all built on top of it. Learn it once and it pays off everywhere.

Your first array

You create an array from a list with np.array(...). By convention everyone imports NumPy as np.

Create a 1-D NumPy array from a list
import numpy as np

prices = np.array([60, 80, 120, 140])

print(prices)
print(type(prices))
print('shape:', prices.shape)

Note: Output: [ 60 80 120 140] <class 'numpy.ndarray'> shape: (4,) The array holds four numbers. Its type is ndarray (n-dimensional array). The shape (4,) means “4 items in one row”.

The big difference: maths on the whole array

With a list, multiplying by 2 just repeats it. With an array, it does real maths on every number at once. Watch the contrast:

Same operation, very different result
my_list  = [60, 80, 120, 140]
my_array = np.array([60, 80, 120, 140])

print(my_list * 2)     # a list just repeats itself
print(my_array * 2)    # an array doubles every number

Note: Output: [60, 80, 120, 140, 60, 80, 120, 140] [120 160 240 280] The list got longer (repeated). The array doubled each value — exactly what you want for maths. This is the whole reason arrays exist.

Python listNumPy array
Best forMixed items (text, numbers)Lots of numbers
Maths on all itemsManual loop neededBuilt-in & instant
Speed on big dataSlowVery fast
Used byGeneral PythonPandas, ML, charts

Tip: Rule of thumb: a bag of mixed things → use a list. A column of numbers you will do maths on → use a NumPy array (or a Pandas column, which is an array underneath).

Q. What does np.array([1, 2, 3]) * 2 produce?

Answer: A NumPy array applies the maths to every element, so each number is doubled: [2 4 6]. A plain list would repeat instead.

✍️ Practice

  1. Make an array of five test scores and print its .shape.
  2. Create a list and an array of [10, 20, 30], multiply each by 3, and compare the two outputs.

🏠 Homework

  1. In two or three sentences, explain to a classmate why NumPy arrays are better than lists for working with thousands of numbers.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →