An array stores values that you can access by index. In PyTorch, the everyday array is a tensor: a multidimensional collection of numbers. A one-dimensional tensor needs one index to select a value; a two-dimensional tensor needs two. Its shape gives the size of each dimension, in order. A tensor with shape (3, 2), for example, has three rows of two values. section 3.2 section 3.1
Three points in one array
```python import torch points = torch.tensor([[4.0, 1.0], [5.0, 3.0], [2.0, 1.0]]) points.shape # torch.Size([3, 2]) points[0, 1] # tensor(1.) points[0] # tensor([4., 1.]) ``` Each row holds a point’s two coordinates. The first index selects a row; the second selects a coordinate within it. Indices start at zero. Selecting a whole row returns another tensor. section 3.2.3
A Python list can also hold indexed numbers, but its elements are separately allocated Python objects. Ordinary PyTorch tensors hold numbers of one type in numerical storage, making large collections and mathematical operations more efficient. Like NumPy arrays, they support multidimensional indexing; unlike a simple list, they also provide operations such as broadcasting. Broadcasting applies an element-wise operation to compatible shapes—for example, adding one scalar to every value or multiplying a 1 × 3 array by a 3 × 1 array to produce a 3 × 3 result. section 3.6 section 3.4
Indexing need not copy the numbers. A tensor can be a view of the same underlying storage, described by its shape, storage offset, and strides. Changing a selected row can therefore change the original array; use `clone()` when an independent copy is needed. The same tensor operations can run on a CPU or GPU after placing the data on the chosen device. section 3.9.1 section 3.10.1
Figure 3.4 Tensors are views of a Storage instance.
The storage diagram helps show why differently shaped tensor views can refer to the same numbers without copying them. section 3.8
Arrays make data usable by neural networks: images, time series, and text can be converted into appropriately shaped numerical tensors. Network inputs, outputs, intermediate values, and parameters are all represented this way. section 4.0 section 3.0







































