title: Shape of tensor for 2D image in Keras
body: <p>I am a newbie to Keras (and somehow to TF) but I have found shape definition for the input layer very confusing.</p>
  
  <p>So in the examples, when we have a 1D vector of length 20 for input, shape gets defined as</p>
  
  <pre><code>...Input(shape=(20,)...)
  </code></pre>
  
  <p>And when a 2D tensor for greyscale images needs to be defined for <a href="https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py" rel="nofollow noreferrer">MNIST</a>, it is defined as:</p>
  
  <pre><code>...Input(shape=(28, 28, 1)...)
  </code></pre>
  
  <p>So my question is why the tensor is not defined as <code>(20)</code> and <code>(28, 28)</code>? Why in the first case a second dimension is added and left empty? Also in second, number of channels have to be defined?</p>
  
  <p>I understand that it depends on the layer so Conv1D, Dense or Conv2D take different shapes but it seems the first parameter is implicit?</p>
  
  <p>According to <a href="https://keras.io/layers/core/#dense" rel="nofollow noreferrer">docs</a>, Dense needs be <code>(batch_size, ..., input_dim)</code> but how is this related the example:</p>
  
  <p><a href="https://keras.io/getting-started/sequential-model-guide/" rel="nofollow noreferrer">Dense(32, input_shape=(784,))</a></p>
  
  <p>Thanks </p>