Difference between the code and why is my code wrong

It is an interesting question that has come up before. It turns out that your method scrambles the data. It depends on the mechanics of how the “reshape” operation works. Just ending up with the correct shape is not good enough. Here’s a thread which explains this in detail.