Pytorch Tensors
Learn about Python tensor: what they are and how do we code them?
We'll cover the following...
Before we can use PyTorch we need to import the Python torch
module. Luckily, Educative’s code widget has PyTorch
ready for us to use simply by importing it. There’s no need to go through a complicated installation process.
import torch
Plain Python vs. PyTorch
A good way to start understanding PyTorch is to compare its basic units of information with plain Python.
Normal Python variables
In plain Python, we use variables to store numbers. We can use these variables like mathematical symbols to calculate new values and store these in new variables if we want to.
Have a look at the following plain Python code:
# normal python variablesx = 3.5y = x*x + 2print(x, y)
We create a variable called x
and give it a value . We then create a new variable called y
and give it a value that is calculated from the expression ...