A vector is just an ordered list things. A vector’s elements are typically either numbers:
v=[123]
...or other vectors:
v=[[123][123]]
A matrix is a grid of numbers:
M=[475869]
A tensor generalizes vectors and matrices.
We refer to items within a vector by its index, starting with 1: v1=1 in the above.
We refer to items within a matrix by its row and column, in that order: M1,2=5.
If we think of vectors as “an object with a single index” and matrices as “an object with two indexes”, a tensor just abstracts that into N indices. That N is called the tensor’s rank: a vector is a rank 1 tensor, and a matrix is a rank 2 tensor.
We call the number of elements in a vector its size, or its dimensionality. The terms are essentially interchangeable, though I find I tend to use “size” more when talking about the mechanics of math operations, and “dimensionality” more when talking about how much information the vector carries.
Lastly, we can treat a vector of size d as a matrix of size 1×d or d×1.
In math and physics, tensors have other properties. We don’t need them, so you can basically think of a tensor as “like a matrix, but with more than two indices.”
There are just a few operations we’ll need to understand:
Two that come up all the time (so make sure you understand them well!):
dot products on vectors
matrix multiplication
A few simple ones that come up less frequently:
matrix transposition
adding matrices and multiplying a matrix by a scalar
Note that all of these work on vectors or matrices, not higher-rank tensors. When we work with higher-rank tensors, we’ll use some indices to slice those tensors into vectors or matrices, and then apply the above operations to those slices. For example, given a rank-3 tensor Xk,i,j, we can think of each Xk,… as a matrix, and then apply some matrix operation to each one.
dot products
Combines two vectors into a single scalar. Both vectors must be the same length.
v⋅w=scalar number
matrix multiplication:
Combines two matrices into another matrix. The first matrix’s column length has to be the second matrix’s row length. The result has the same number of rows as the first matrix, and the same number of columns as the second.
Aa×b⋅Bb×c=Ca×c
The expression A⋅B can also be written as just AB.
transposition
Swaps a matrix’s rows and columns, which you can visualize as flipping along its ╲ diagonal. This is denoted as AT.
[142536]T=⎣⎡123456⎦⎤
adding matrices
We can add two or more matrices as long as they’re the same size. This just means adding their corresponding elements:
[142536]+[104020503060]=[114422553366]
Adding vectors works the same way: we just treat an n-vector as a 1×n matrix:
[123]+[102030]=[112233]
multiplying by a scalar
We can multiply a matrix (or vector) by a scalar, which just means applying the multiplication to each element:
A dot product combines two vectors of the same size (dimensionality) into a single number.
The two vectors are often represented as a horizontal vector on the left and a vertical vector on the right, but that’s just a convention. It only matters that they have the same number of elements.
The dot product is simply the sum of terms, where each term the product of the two vectors’ corresponding elements:
[abc]⋅⎣⎡αβγ⎦⎤=a⋅α+b⋅β+c⋅γ
If the two vectors are normalized to have the same magnitude, the dot product specifies how aligned they are: higher values means more aligned.
In the matrix multiplication of two matrices A and B, each cell (i,j) is the dot product of the corresponding row i from A and column j from B. This produces a thorough mixing of the two inputs: every row from A gets combined with every column from B.