Arrays with NumPy

As soon as we move beyond small examples, plain Python lists start to feel awkward for numerical work. AI systems deal with vectors, grids, and tables of numbers, and they do so at scale. This lesson exists to orient us to NumPy arrays, which are the basic building block for numerical data in Python-based scientific and AI workflows.

What a NumPy array is

A NumPy array is a compact, efficient structure for storing numerical data. Unlike a Python list, an array is designed for math first, not general-purpose storage.

We can think of an array as a block of numbers arranged in a regular shape, such as a line of values or a grid. This regularity is what allows NumPy to work quickly and predictably with large datasets.

import numpy as np

values = np.array([1, 2, 3, 4])

Here we create a one-dimensional array containing four numbers.

Creating arrays from Python data

NumPy arrays are often created from existing Python data. Lists and nested lists are the most common starting point.

A single list becomes a one-dimensional array. A list of lists becomes a multi-dimensional array, as long as the structure is regular.

import numpy as np

temperatures = np.array([288.0, 210.0, 165.0])

grid = np.array([
    [1, 2, 3],
    [4, 5, 6]
])

This allows us to move from familiar Python data into a form that NumPy can process efficiently.

Accessing and modifying array elements

Array elements are accessed using index notation, much like lists. The difference is that arrays extend naturally to multiple dimensions.

import numpy as np

distances = np.array([58, 108, 150])

first = distances[0]
distances[2] = 152

For multi-dimensional arrays, we provide one index per dimension.

value = grid[1, 2]

This retrieves the value from the second row and third column.

Array shape and dimensionality

Every NumPy array has a shape, which describes how many dimensions it has and how large each dimension is. Shape is central to understanding how an array represents data.

import numpy as np

data = np.array([
    [1.0, 0.3],
    [0.8, 0.6],
    [0.2, 0.9]
])

print(data.shape)

The shape tells us how many rows and columns are present. This information becomes critical when arrays are used to represent vectors, matrices, or batches of inputs in AI systems.

Using arrays to represent numerical data

NumPy arrays are used to represent almost all numerical data in scientific Python. Measurements, features, coordinates, and signals are all commonly stored as arrays.

Instead of thinking in terms of individual values, we start thinking in terms of whole collections of numbers that move through our programs together.

import numpy as np

planet_radii = np.array([2439, 6051, 6371, 3389])

This single array can now stand in for a dataset that later feeds into calculations, models, or visualizations.

Conclusion

At this point, we are oriented to what NumPy arrays are, how they are created, and how they store numerical data. We can recognize array shapes, access elements, and see why arrays matter for AI-relevant computation. That foundation is enough to move on to using arrays as computational tools, rather than just containers.