An array holds values in one or more dimensions. In deep learning, inputs must first become arrays of numbers: image pixels can become floating-point values, while text can become sequences of integer vocabulary indexes. PyTorch calls its multidimensional numeric arrays tensors. They resemble NumPy arrays, but PyTorch tensors also support GPU-accelerated training. section 2.1.1 section 2.1
Start with one dimension
Store the heights of 46 U.S. presidents in a PyTorch tensor. Its shape is (46): one dimension containing 46 values. Square brackets select a value, while a slice such as `heights_tensor[-5:]` selects the last five. Use `dtype=torch.float64` when creating the tensor if that precision is wanted; it offers greater precision than the default `float32` at a computational cost. section 2.1.1 section 2.1.2 section 2.1.3
Shape determines how values are arranged and which operations fit. Convert the heights to feet, concatenate the two measurements, then reshape the 92 values into a (2, 46) array: one row per unit and one column per president. Now two indexes select one value, and `torch.mean(heights_reshaped, dim=1)` calculates a mean for each row. Check shapes before operating on tensors; mismatches cause errors. section 2.1.3 section 2.1.4
Listing 3.1 Creating training data to form an exponential growth shape
import torch torch.manual_seed(0) #1 observations = 2048 train_data = torch.zeros((observations, 2)) #2 train_data[:,0]=50*torch.rand(observations) #3 train_data[:,1]=1.08**train_data[:,0] #4
This two-dimensional training array starts with 2,048 rows and two columns. Column indexing fills the first column with sampled x values and the second with values on an exponential growth curve. section 3.2.1
Arrays also carry less tabular inputs. For clothing-image classification, `ToTensor()` converts image values from integers between 0 and 255 to floats between 0 and 1; normalization then maps them to the range −1 to 1. For music generation, a piece can instead be represented as a four-dimensional object with shape (4, 2, 16, 84). The useful shape depends on what the model must process or produce. section 2.2.2 section 13.1







































