I have training data where each example is a 12x3 two-dimensional array. Let's say I have 1000 of these training examples so my input matrix is a three-dimensional 1000x12x3 matrix. I am trying to feed this into a Neural Network (similar to the one outlined in the diagram below). However the first layer of the neural net is expecting the input matrix to be two dimensional since the hidden layer with which it will be multiplied is also two-dimensional.

How do I resolve this? Should I force each input example to be single dimensional, by flattening it out into a 1x36 array? Or should the hidden layers themselves be three-dimensional in order to match the input?

  • $\begingroup$ Are you familiar to CNNs? $\endgroup$ Commented Jul 26, 2018 at 16:49
  • $\begingroup$ @Media I don't think this a cnn problem...The OP is probably confusing that in a NN flattening the array will not result in any change of results $\endgroup$
    – DuttaA
    Commented Jul 27, 2018 at 1:46
  • $\begingroup$ Maybe, but the subsequent layers are like what we see in CNNs. $\endgroup$ Commented Jul 27, 2018 at 5:23

2 Answers 2


The most common options are:

  1. Change the input shape. Use numpy.reshape to transform the original shape three-dimensional into a two-dimensional.

  2. Change the model architecture. Each layer that receives a three-dimensional representation will have to be three-dimensional size or add a layer than learns a two-dimensional representation.


You wouldn't input all of the examples into one layer at once. You input the first example, feed it forward then feed it backward, then you input the next example and so on. Like the neural network needs to be able to actually learn you can't just run one iteration and have it make accurate predictions.

If you're doing it from scratch it would look something like

input_data = np.array() #shape of 1000x12x3
for i in range(1000):
    neuralnet = neuralnet(input=input_data[i]) #input data with shape 12x3

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.