Python Deep Learning Keras: Wrong number of dimensions: expected 3, got 2 with shape
Question: I am new to Keras, a deep learning library and need your help. The model is
built without errors, but has the following issue when calling model.fit(X,
y):

    
    
    TypeError: ('Bad input argument to theano function with name "~/machine_learning2/lib/python2.7/site-packages/keras/backend/theano_backend.py:380"  
    at index 0(0-based)', 'Wrong number of dimensions: expected 3, got 2 with shape (16, 40).')
    

This is similar as this one <https://github.com/fchollet/keras/issues/815> My
y train matrix is a matrix with multiple rows and one column.

One solution mentioned about converting y to 3d tensor with binary one-hot
coding. Is there an example of this?


Answer: You can use:

    
    
    from keras.utils import np_utils
    np_utils.to_categorical(y_train, n_classes)
    

for one hot encoding, where y_train is a train class vector and n_classes -
total number of a classes,

However, based on that the error description mentions (16, 40), rather than a
(Nx1), I suspect you might have an issue with your X as well.

