Tensors are multi-dimensional arrays that can represent scalars, vectors, matrices, and higher-dimensional data. They enable efficient computation on hardware like GPUs and CPUs, which is crucial for machine learning.
import tensorflow as tf x = tf.constant([[1, 2], [3, 4], [5, 6]]) y = tf.constant([10, 20]) result = x + y
The tensor 'x' has shape (3, 2). The tensor 'y' has shape (2,). TensorFlow broadcasts 'y' to match 'x' along the first dimension, so the result shape is (3, 2).
TensorFlow typically uses the shape (batch_size, height, width, channels). For grayscale images, channels = 1. So the correct shape is (64, 28, 28, 1).
Increasing batch size increases the first dimension of the input tensor, meaning more samples are processed simultaneously. This requires more memory but can lead to smoother gradient updates.
Comparing predictions and labels element-wise: correct at positions 0, 2, and 3 (3 correct out of 4). Accuracy = 3/4 = 0.75.