AI ProgrammingAcademy
Back to Samples

Optional Math: Vectors and Matrices

Understand lists, tables and weighted sums before seeing formal linear algebra in Professional. Optional support only—not a prerequisite for exams or certificates.

Learning Objectives

  • Read a vector

    Treat a vector as an ordered list of measurements with a consistent meaning for each position.

  • Calculate a dot product

    Multiply matching entries and add them to form a weighted sum.

  • Read a matrix shape

    Count rows and columns and check compatible dimensions.

Core Concepts

1. A vector is an ordered list

A vector such as [2, 3] can represent two features: hours studied and exercises completed. Position matters: [3, 2] describes a different observation. Choose consistent units and feature order across all examples.

features = [2, 3]
print(len(features))  # 2 features

2. Multiply matching entries and add

A dot product is a weighted sum. For features [2, 3] and weights [4, 1], multiply 2 × 4 and 3 × 1, then add 8 + 3 = 11. Both vectors must have the same length.

features = [2, 3]
weights = [4, 1]
if len(features) != len(weights):
    raise ValueError("Lengths must match")
score = sum(x * w for x, w in zip(features, weights))
print(score)  # 11

3. A matrix is a table of numbers

A matrix with 3 rows and 2 columns has shape 3 × 2. Rows can be examples and columns can be features. Multiplying a 3 × 2 matrix by a 2-entry weight vector produces 3 scores, one per row. The inner dimensions must match.

examples = [[2, 3], [1, 4], [0, 5]]
weights = [4, 1]
for row in examples:
    print(sum(x * w for x, w in zip(row, weights)))
# 11
# 8
# 5

4. Understand scale and distance

If one feature uses thousands and another uses fractions, the large feature can dominate a distance calculation. Scaling makes comparisons more meaningful; it does not automatically remove bias. Embeddings are longer numerical vectors that represent content, not a list of readable words.

When this helps: This is a gentle bridge to Professional linear algebra, embeddings and clustering. It is not required before starting Foundations.

Practice Exercise

Calculate two weighted scores

Use weights [2, 1] for observations [3, 4] and [1, 5]. Check both dimensions and calculate one score per observation.
rows = [[3, 4], [1, 5]]
weights = [2, 1]
# Check lengths and print each weighted sum

Concept Quiz

Test your understanding with this quiz. Select the best answer for each question.

1. What is the dot product of [1, 2] and [3, 4]?

2. A table contains 5 examples and 3 features per example. What is its shape?

Are there any issues that Customer Support should be aware of?

Help optimize our AI programming lessons to ensure student success!

Sign in to send a comment to Customer Support.

Hide Icons