Skip to content
Advertisement

ValueError: shapes (240000,28,28) and (2,512) not aligned: 28 (dim 2) != 2 (dim 0)

I’m making a CNN and I’ve got this error that the matrices don’t align and i understand the error but i don’t know how to fix it. Here is the code:

JavaScript

And this is the error i get in sublime text:

JavaScript

As you can see it gets to epoch 1 then when trying to do the numpy dot product and then cant do it.

I’d appreciate any help

Thanks :)

Advertisement

Answer

Firstly, you should flatten your input so its shape is (240000, 28*28) = (240000, 784). After that, the problem is in this line:

JavaScript

You set your input size to 2, when it should be 784 which is the number of pixels in each image (assuming you’re using MNIST).

JavaScript

Should work correctly if your inputs are flattened.

Edit: To flatten your inputs I would use np.reshape as demonstrated here https://stackoverflow.com/a/18758049/11777402.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement