Week2 assignment2 flattening img

In Week2 Assignment2 ex-2 I wrote:

why does the code above donot work ?
I wrote this code as we did in assignment1 while performing image2vector in ex5.

Hello Devansh,

Your codes are incorrect for exercise cell 2.

Please refer this image which are instructions mentioned before the exercise cell-2 to make correction in your codes.

This will help you to write the correct codes.

Most important thing, we are not suppose to post codes on public post. Kindly remove codes from your post. You can share either screenshot of your error log in case you encounter error or share the screenshot of your output with the expected output when you have different output than the expected output.

Just let me know once issue is resolved.

Keep Learning!!!


It’s an interesting question that has come up before. It turns out that just getting the correct output shape is not enough: your method actually scrambles the data, because it doesn’t preserve the “samples” dimension. Here’s a thread which explains this in detail.

Glad that you could do corrections with the hints. Paul’s explanation is in detail to understand why and how transpose differ from your code than the right code. you basically had vectorised and then tried to reshape causing the error.

Go back and check @paulinpaloalto response on the thread he has shared. open your local Jupyter notebook and do these function matrix yourself. You will understand this more and remember always.


1 Like

ok thankyou mam.

thankyou to both @paulinpaloalto sir and @Deepti_Prasad ma’am.
thankyou for your responses.
thankyou @Deepti_Prasad mam the above code runs perfectly and i hv removed the code!