Loading...
A vector is an ordered collection of components from a defined field. It can represent a point, a direction or numerical features, but its interpretation is part of the model.
What you'll be able to do
An n-vector over the reals has n real-valued components in a fixed order. A list or one-dimensional array stores those components by index. A function view maps an index set such as {0,1,2} to component values; a dictionary can implement that indexed mapping.
Dimension matters: adding a two-component vector to a three-component vector is not defined by ordinary componentwise addition. A geometric vector can be drawn as an arrow from the origin, but a higher-dimensional feature vector need not describe physical space.
Vector addition adds corresponding components, while scalar multiplication multiplies each component by the scalar. Adding a displacement to a point can represent translation; multiplying by a scalar changes scale. A negative scalar also reverses direction in a geometric interpretation.
A convex combination αu+βv requires non-negative weights with α+β=1. It lies between the two endpoints in the geometric model. If the weights do not sum to one, the result is still a linear combination but need not have that interpolation interpretation.
The dot product adds products of corresponding components, yielding a scalar. For non-zero geometric vectors, u·v=|u||v|cos θ connects it to their angle. Perpendicular non-zero vectors have zero dot product. A zero vector has no defined direction, so the angle formula cannot divide by its zero magnitude.
In a computing model, dot products can combine feature weights or measure directional similarity. State whether lengths should be normalised before comparing different vectors. The same arithmetic can support different tasks, so explain what a large or small result means in the given context.
u = [2, 1]
v = [1, 3]
dot = sum(a * b for a, b in zip(u, v))
midpoint = [(a + b) / 2 for a, b in zip(u, v)]
print(dot, midpoint)Scroll horizontally to see the full code or table.Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.