Chapter 3: PyTorch Tensors

Installing PyTorch

face Luca Grillotti

PyTorch Tensors

In the previous chapters, all the variables manipulated in our gradient descent algorithm were of type float.

To make all our operations vectorisable, we group our data into multi-dimensional matrices called tensors.

In this course, as in a high majority of courses provided in the Department of Computing, we will use PyTorch as a Machine Learning framework. Hence, all our data will be grouped into torch tensors (of type torch.Tensor).

Installing PyTorch

Before implementing anything, let’s install torch.

$ pip3 install torch torchvision numpy  # numpy sometimes does not come with `torch` 

If you want to do that in a virtual environment venv_pytorch (recommended):

$ python3 -m venv venv_pytorch
$ source venv_pytorch/bin/activate
(venv_pytorch) $ pip install torch torchvision numpy