Week 4, A2: Shape of input tensors

According to the compute_content_cost function description the a_C is supposed to have 4 dimensions:

a_C – tensor of dimension (1, n_H, n_W, n_C), hidden layer activations representing content of the image C

However the test input has one more dimension:
a_C = tf.random.normal([1, 1, 4, 4, 3], mean=1, stddev=4)

The dimension is then lost inside the function by indexing the last (and only) element of the first dimension: a_C = content_output[-1]


  1. Is the function argument description mistaken by stating the 4-dimensional shape, when it seems to actually expect 5-dimensional tensor?
  2. What does the lost dimension stand for? I understand the remaining four are m, h, w, c as usual.
  3. Why do we use this fifth dimension only to immediately lose it at the function’s beginning?

Take a look at how the cost functions are used later in the notebook. The extra first dimension on the input tensors is for the layers. They are sampling the outputs of multiple hidden layers of the network.