An R array stores values along one or more axes. It is R’s built-in implementation of a tensor, the basic data structure used to represent data in neural networks. A vector has one axis; a matrix has two. More axes let an array represent sequences, images, and batches of data. section 2.2 section 2.2.2 section 2.2.3
Make a two-axis array
Run `x <- array(seq(2 * 3), dim = c(2, 3))`. The result has two rows and three columns: its first row is `c(1, 3, 5)`, and its first column is `c(1, 2)`. Check its rank with `length(dim(x))`, which returns `2`. section 2.2.3
Three attributes help describe any array: rank is its number of axes, shape gives the size of each axis, and data type identifies the kind of values stored. For an R array `x`, inspect these with `length(dim(x))`, `dim(x)`, and `typeof(x)`. A shape of `(2, 3)` means two entries along the first axis and three along the second; it does not mean rank 3. section 2.2.5 section 2.2.3
Choose axes to match what each entry represents:
- Tabular vector data: `(samples, features)`. A dataset of 100,000 people described by three attributes has shape `(100000, 3)`. section 2.2.8
- Sequences: `(samples, timesteps, features)`; images: `(samples, height, width, channels)`; video: `(samples, frames, height, width, channels)`. section 2.2.8
The MNIST training images illustrate why shape matters: 60,000 grayscale images of 28 × 28 pixels form a rank-3 array with shape `(60000, 28, 28)`. Before feeding them to a Dense-layer network, reshape them to `(60000, 28 * 28)` and divide their pixel values by `255`. Their labels are a separate array, with one label per image. section 2.1 section 2.2.5
Listing 2.4 Preparing the image data
train_images <- array_reshape(train_images, c(60000, 28 * 28)) train_images <- train_images / 255 test_images <- array_reshape(test_images, c(10000, 28 * 28)) test_images <- test_images / 255
The preprocessing code turns each image grid into a row of values for the network and scales its pixel values. section 2.1
R arrays can be passed to Keras and its deep learning backends; they are automatically converted to NumPy arrays at that boundary. NumPy arrays offer additional data types and array-operation behaviors, so the two representations are useful in different parts of a workflow. section 2.2







































