title: Keras Dense layer Output Shape
body: <p>I am unable to understand the logic behind getting the output shape of the first hidden layer. I have taken some arbitrary examples as follows;</p>
  
  <p>Example 1:</p>
  
  <pre><code>model.add(Dense(units=4,activation='linear',input_shape=(784,)))  
  model.add(Dense(units=10,activation='softmax'))
  model.summary()
  
  Model: "sequential_4"
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  dense_7 (Dense)              (None, 4)                 3140      
  _________________________________________________________________
  dense_8 (Dense)              (None, 10)                50        
  =================================================================
  Total params: 3,190
  Trainable params: 3,190
  Non-trainable params: 0
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>model.add(Dense(units=4,activation='linear',input_shape=(784,1)))   
  model.add(Dense(units=10,activation='softmax'))
  model.summary()
  Model: "sequential_6"
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  dense_11 (Dense)             (None, 784, 4)            8         
  _________________________________________________________________
  dense_12 (Dense)             (None, 784, 10)           50        
  =================================================================
  Total params: 58
  Trainable params: 58
  Non-trainable params: 0
  </code></pre>
  
  <p>Example 3:</p>
  
  <pre><code>model.add(Dense(units=4,activation='linear',input_shape=(32,28)))    
  model.add(Dense(units=10,activation='softmax'))
  model.summary()
  Model: "sequential_8"
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  dense_15 (Dense)             (None, 32, 4)             116       
  _________________________________________________________________
  dense_16 (Dense)             (None, 32, 10)            50        
  =================================================================
  Total params: 166
  Trainable params: 166
  Non-trainable params: 0
  </code></pre>
  
  <hr>
  
  <p>Example 4:</p>
  
  <pre><code>model.add(Dense(units=4,activation='linear',input_shape=(32,28,1)))    
  model.add(Dense(units=10,activation='softmax'))
  model.summary()
  Model: "sequential_9"
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  dense_17 (Dense)             (None, 32, 28, 4)         8         
  _________________________________________________________________
  dense_18 (Dense)             (None, 32, 28, 10)        50        
  =================================================================
  Total params: 58
  Trainable params: 58
  Non-trainable params: 0
  </code></pre>
  
  <p>Please help me in understanding the logic.</p>
  
  <p>Also, I think the rank of <code>input_shape=(784,)</code> and <code>input_shape=(784,1)</code> is the same then why is their <code>Output Shape</code> different?</p>