PyTorch is a Python library for building deep learning projects. Its core data structure is the tensor, a multidimensional array for holding numbers, vectors, matrices, and more. The torch module provides operations on tensors, so you can express and run computations in familiar Python code. section 1.3 section 1.5
To create a tensor, import torch and call a function such as torch.ones. You can then read or change individual values using zero-based indexing: section 3.2.2
# In[4]: import torch #1 a = torch.ones(3) #2 a # Out[4]: tensor([1., 1., 1.]) # In[5]: a[1] #3 # Out[5]: tensor(1.) # In[6]: float(a[1]) # Out[6]: 1.0 # In[7]: a[2] = 2.0 #4 a # Out[7]: tensor([1., 1., 2.])
Create a three-element tensor, inspect one value, and change another. section 3.2.2
The torch library also provides mathematical functions that operate element-wise on tensors. For practice, find a function such as cosine or square root, apply it to a tensor, and investigate whether an in-place version is available. section 3.15
Tensors and their operations can run on a CPU or GPU. PyTorch can also track numerical operations and use that history to calculate how an output changes when inputs change. Its automatic differentiation engine, autograd, handles these calculations for optimization during training. section 1.5
A typical project loads data, defines and trains a model, and evaluates or deploys it. PyTorch emphasizes immediate execution and an approachable Python API; much of its performance-oriented implementation is written in C++ and CUDA. section 1.5 section 1.8
Figure 1.2 Basic, high-level structure of a PyTorch project, with data loading, training, and deployment to production
See how data loading, training, and deployment fit together in a PyTorch project. section 1.5













