PyTorch Tensors
code
ML
This project serves as an introduction to PyTorch and tensors.
GOAL
Learn more about the Machine Learning framework known as PyTorch.
RESULT
A better understanding of PyTorch and what tensors are.
This walkthrough is my interpretation of the official PyTorch tutorial on tensors.
Tensors
Tensors are a data structure similar to arrays and matrices. PyTorch uses tensors to encode both the inputs and outputs of a model as well as model parameters.
Tensors are like NumPy arrays, but tensors can be run on GPUs and are also optimized for automatic differentiation.
Load in the libraries
Initializing a Tensor
Tensors can be initialized in various ways, like so:
Directly from data:
From a NumPy array:
From another tensor:
Code
Ones Tensor:
tensor([[1, 1],
[1, 1]])
Random Tensor:
tensor([[0.4359, 0.1517],
[0.9181, 0.1814]])