# Week 4 Assignment 2 - compute_layer_style_cost

Hello
W4 Assignment 2, exercise 3 has an additional hints that talks about the shape of unrolled matrix before itβs inputed into the Gram function

• Since the activation dimensions are (π,ππ»,ππ,ππΆ) whereas the desired unrolled matrix shape is (ππΆ,ππ»βππ), the order of the filter dimension ππΆ is changed. So `tf.transpose` can be used to change the order of the filter dimension.

What happens to the samples after unrolling? shouldnβt it be (nC, nHβnWβm)? (nC, nHβnW) is missing a fourth dimension.

Actually the way the instructions are written is a little misleading. If you actually check how they use compute_layer_style_cost, youβll find that they only call it for one sample at a time. You can actually add an assertion that m is either 1 or None.

@paulinpaloalto
Thanks for the answer. I am somehow very stuck. I understand that I need to transpose and then reshape. The dimensions work as intended:

The [m, n_H, n_W, n_C] becomes [n_C, n_Hβn_Wβm] βm is 1β. I used -1 in reshape so it doesnβt matter if m is provided or not. But my final number is very large (2808.4368). I have spent an exorbitant amount of time on this issue to no avail. Could you please take a look at my solution?

Please be aware that the mentors are just fellow student volunteers. We do not have any magic powers to look at anyone elseβs notebooks.

Understood. I was just trying to find a way out, didnβt actually thought you can access my file.

I canβt believe my mistake! I forgot that β^β this is NOT power in python. Itβs double asterisk **
I spent +12 hrs on this

3 Likes

Glad to hear you found the answer! If itβs any comfort, there was another thread by someone making that same mistake recently on this very exercise.

Absolutely unbelievable. Thank you so much, anyways.

Damnβ¦ I was stuck in exactly the same spot. In fact, I searched the threads for 2808 because thatβs exactly the answer I got as well. Thank you so much.

1 Like

thank you. its help me a lot!

I did exactly the same mistake and also had spent a lot of time to find what is the problem.