I have implemented a simple neural network with keras that takes an input of 50 values and returns a classification of '0' or '1'. I believe the model is expecting an input shape of (50, 1). I'd like to add another 50 data values for each input, but I'd like them to be associated with the original 50 respective inputs. So instead of making the input of shape (100, 1), I guess I'd like to make it of shape (50, 2). I would like the neural network to know from the start that each input feature has two values associated with it, instead of it thinking there are 100 separate input features. Here's what I have so far:

model = Sequential()
model.add(Dense(50, input_dim=50, kernel_initializer='normal', activation='relu'))
model.add(Dense(100, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal', activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

Can anyone show me the way the alter this structure to accept my new input shape?


1 Answer 1


If you want to use a simple neural network which takes in a 50x2 matrix you can do this y flattening your matrix to a 100x1 vector. This will make no difference in the way that the neurons are processed. Each neuron will take all the inputs and make a decision on its weight accordingly.

If you want some neighborhood feature selection then you can use a convolutional neural network like

model = Sequential()
model.add(Conv2D(32, kernel_size=(2, 2),
model.add(Conv2D(64, (2, 2), activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dense(128, activation='relu'))
model.add(Dense(1, activation='softmax'))


This will do a feature mixing within a 2x2 window across your matrix which will thus mix your two values before feeding them to the deeper part of the network.

Doing this is also a good idea as it serves as a means to reduce the complexity of your model which may lead to better results.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.