Course 4 Week 2 Assignment 1 Identity BLOCK shape?

I passed the coding even though am unable to wrap my head around the shape of identity output.

As X1,X2 and X3 are concatenated

X1 = np.ones((1, 4, 4, 3)) * -1
X2 = np.ones((1, 4, 4, 3)) * 1
X3 = np.ones((1, 4, 4, 3)) * 3
X = np.concatenate((X1, X2, X3), axis = 0).astype(np.float32)

shouldnt the shape of X and X_shortcut be 12 * 4 * 3 to result in identity output of same shape after applying RELU?

Instead output (After applying RELU) appears to be of shape 2 * 4 * 3

[[[ 0. 0. 0. 0. ]
[ 0. 0. 0. 0. ]]

[[192.71234 192.71234 192.71234 96.85617]
[ 96.85617 96.85617 96.85617 48.92808]]

[[578.1371 578.1371 578.1371 290.5685 ]
[290.5685 290.5685 290.5685 146.78426]]]

Since we concatenate along the first dimension (axis=0), the dim of X and X_shortcut is (3, 4, 4, 3). You can always add print(X.shape) statements to the code to better understand operations.

Ok thanx that explains the 3 different ararays( 3 diff examples) , however, shouldnt each one them be 4 * 4 shape rather than 2 * 4 shape?

will appreciate if u can explain how the output shape corresponds to 3,4,4,3 as to me they appear 2 rows and 4 columns for each 3 examples
…thanx in advance

The print statement is not printing the full tensor A:

print(np.around(A3.numpy()[:,(0,-1),:,:].mean(axis = 3), 5))

which is why the shapes don’t match your expectation.

Perfect got it. Mean is taken along column(axis 3) dimension and than printing only 1st and last example (0,-1)from each channel…thank you so much :slight_smile:

1 Like