Course 1, Week2, reshape problem

Hi everyone!
I am having a problem with reshape. Why isn’t
X.reshape(X.shape[0], -1).T equivalent to X.reshape(-1, X.shape[0])? I think they should be mathematically the same. But I keep getting an error that asks me to use the suggested one. In addition, the error is that same when I try to use X.reshape(X.shape[1]*X.shape[2]*X.shape[3], X.shape[0]) explicitly.

They are not mathematically equivalent. Just because the shapes are the same, does not mean the contents are the same. It all depends on how reshape works. Here’s a thread which explains this in detail.

1 Like

Oh right. Thank you a lot. I understood it by looking at the mechanism (order) of putting the elements of the old tensor to the tensor of the new size.