Week1 conv_forward: A_prev has a strange shape to me?


I’m used to seeing 4D matrix array in the following format:

(select which 3d matrix you want, select the depth of this 3d matrix, select the rows, select the columns).

However, A_prev has shape: (m, n_H_prev, n_W_prev, n_C_prev) == (select which 3d matrix you want, select the rows, select the columns, select the depth of this 3d matrix), so different to what I’m used to working with.

My question is; when dealing with arrays can we define anyone of the values (a,b,c,d) to be in what ever order we want e.g. (m, n_C_prev, n_W_prev, n_H_prev), as long as when we call these positions we refer back to the defined shape?

e.g. using: A_prev(m, n_C_prev, n_H_prev, n_W_prev) = A_prev(3, 4, 8, 7)
I want the first 2 rows and columns for all depths of the first 3d matrix I would do:
A_prev[0, :, 0:2, 0:2], this would return a 3d matrix of shape (4,2,2).

To extend this question, why is A_prev defined this way (m, n_H_prev, n_W_prev, n_C_prev) and not (m, n_C_prev, n_W_prev, n_H_prev)?


Hi EvilerEarth,

Using (m, n_H, n_W, n_C) is the convention chosen in tensorflow (see e.g. Convolutional Neural Network (CNN)  |  TensorFlow Core), which is the platform used later in the course.