From the course: Machine Learning Foundations: Linear Algebra

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Vector arithmetic

Vector arithmetic

- Arithmetic operations in linear algebra are simple and intuitive. So let jump right into it. We'll start with addition. To add two vectors, simply add each corresponding element. Addition is possible only for two vectors that have the same dimension. We cannot add a three-dimensional vector with a four-dimensional vector. For vector subtraction, the same rule applies. You can subtract the two vectors elementwise only if they have the same dimension. Let's head onto Jupyter Notebooks and try this out. We have already imported numpy as np. We will define three vectors: a, b, and c, and then add vectors a and b, and after try to add vectors a and c. As you can see, when we try to add a and c we get an error because their dimensions don't match. Next, let's subtract a and b, and then try to subtract a and c. We also get an error in case of a and c. We can also multiply two vectors when they have the same length.…

Contents