PyTorch is a Python library for building and training deep learning models. Its core data structure is the tensor, a multidimensional array. The `torch` module provides operations on tensors, so you can express calculations in familiar Python while running them on a CPU or GPU. section 1.0 section 1.5
Tensors can record the operations performed on them. PyTorch’s automatic differentiation engine, autograd, uses that history to calculate how changes to earlier values affect an output—an essential step in training a model. PyTorch also provides facilities for designing neural networks and moving from data loading through training to deployment. section 1.5
# 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.])
This short listing imports `torch`, creates a tensor with `torch.ones(3)`, then reads and changes individual elements. It is a starting point for trying tensor operations interactively. section 3.2.2
For practice, look up a mathematical function such as cosine or square root in `torch` and try applying it element-wise to a tensor. Check whether it also has an in-place version, and investigate any error rather than assuming every input tensor will work. section 3.15










