Source: Deep Learning on Medium
This article is intended to bring a brief understanding on what a tensor is and how does its dimensional representation work
For the sake of simplicity lets create a simple tensor with all ones to help us understand the concept better.But in real world applications the values could be anywhere between -inf to +inf.
Shape of tensor- Term used to define the dimensionalty, similar to shape in pandas DataFrames.
torch.ones : Creates tensor with given dimensions with values filled with ‘1.’
Please go through the command and the tensors printed on the command line in the left and the container representation in the right to get the sense of how tensors build from right to left.Also do read the captions below images
Since it is difficult to visualize more than 3 dimensions, we are trying to represent each dimension by a color
Tensors grow as containers in each dimension
Reason for this blog post- to understand where the brackets end in the tensor print in command line & it is not very obvious as dimensions grow for a beginner to get hang of it.Example below forms foundations for understanding them
Lets increase the value in another dimension
Lets grow the dimensions
The last one with ones
Summary : Always read tensors from right to left.
Example:A tensor of dimension (o,p,q,r) can be interpreted as follows
q such r dimensional tensors form tensor of shape (q,r) and p such (q,r) dimensional tensors from (p,q,r) dimensional tensor and o such (p,q,r) dimensional tensors form tensor of shape — (o,p,q,r). And imagine each of them to be inside containers of other as illustrated
Question to help reinforce understanding:
What would be difference between print of the tensors of dimensions — (4,2,1,2)& (2,4,2,1). Try to do print torch.ones(given dimension) and find the answer on your command line
Further reading :
Gained this understanding while going through pytorch tutorials at