We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Vector Operations

Vectors are lists of numbers that represent points in space. The interesting part is that semantically similar words have vectors that are close together. That means we need vector math to measure how close two vectors are.

Click to play video

Vector Addition

Vector addition is useful for combining concepts. For example: "I want a result that's like this and like that."

With vector addition, we just add the corresponding elements of two vectors together.

[0.5, -0.2,  0.8]
+
[0.1,  0.9, -0.3]
=
[0.6,  0.7,  0.5]

"The Great Bear" embeds to [0.5, -0.2, 0.8] (Animation, Adventure, Family). "Back Country" embeds to [0.1, 0.9, -0.3] (Horror, Thriller, Survival). Add them together and we get [0.6, 0.7, 0.5], a mix of those genres: Family, Adventure, and Horror.

Vector Subtraction

Vector subtraction is useful for removing concepts. For example: "I want a result that's like this but not that."

[0.5, -0.2,  0.8]
-
[0.1,  0.9, -0.3]
=
[0.4, -1.1,  1.1]

"The Great Bear" embeds to [0.5, -0.2, 0.8] (Animation, Adventure, Family). If we subtract "The Revenant," which embeds to [0.1, 0.9, -0.3] (Horror, Thriller, Survival), we get [0.4, -1.1, 1.1], representing Family Adventure but not Horror or Survival.

Assignment

Implement the add_vectors and subtract_vectors functions.