Different Tastes of Matrix Multiplication in Pytorch
Happy quarantine!
I recently started to refresh my knowledge on pytorch. This post is simply to document what I have learned. I will focus on different flavor of matrix multiplication in Pytorch.
First of all: basics for making ice cream
torch.from_numpy() and torch.unsqueeze()
are basics for you to manipulate data in pytorch. See below for examples.
torch.unsqueeze
inserts a new tensor with size of one at the desired position. You can use it to change the dimension of existing tensor.
Level up: torch.expand
expand() can help with generating replicative tensors from singleton. See example below:
Now let’s make ice cream of different flavor!
Vanilla flavor of matrix multiplication: torch.matmul()
This is the basic version
a = torch.randn(2,3)
b = torch.randn(3,4)
c = torch.matmul(a,b)
Next, more fun with torch.chain_matmul
Finally, mega fun with torch.bmm
So what is your favorite?
You can check out the detailed notebook here:
Enjoy your ice cream🍦!