Move data through shapes without losing your sanity
TF supports NumPy-style indexing and slicing identically. Where TF diverges is the dedicated reshape ops — tf.reshape, tf.expand_dims, tf.squeeze, tf.transpose — that you'll use constantly to move tensors through layers.
The batch dimension trick: most TF ops expect a leading batch dim. A single 224×224 RGB image with shape (224, 224, 3) needs to become (1, 224, 224, 3) before feeding into a model. Two equivalent ways: tf.expand_dims(image, axis=0) or image[tf.newaxis, ...].
The -1 trick: tf.reshape(x, [-1]) flattens any tensor to 1D. tf.reshape(x, [batch, -1]) flattens everything except the batch dim — useful right before a Dense layer.