title: Why do we have to import keras from tensorflow if we have already imported tensorflow in python?
body: <p>I'm now learning tensorflow and keras and I see all tutorials have these two imports:</p>
  
  <pre><code>import tensorflow as tf
  from tensorflow import keras
  </code></pre>
  
  <p>Based on my understanding of python import, I thought the second line was an extra, since if we have already imported tensorflow in the first line, then we shall have imported every module in tensorflow. Just like if we have</p>
  
  <pre><code>import math 
  </code></pre>
  
  <p>then we shouldd have math.log(), math.sqrt() available.</p>
  
  <p>However, if I comment</p>
  
  <pre><code>from tensorflow import keras
  </code></pre>
  
  <p>then this line of code</p>
  
  <pre><code>model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
  </code></pre>
  
  <p>would return
  NameErrorTraceback (most recent call last)</p>
  
  <pre><code>&lt;ipython-input-3-740ba65f0ade&gt; in &lt;module&gt;()
  ----&gt; 1 model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
  
  NameError: name 'keras' is not defined
  </code></pre>
  
  <p>Why can't we directly use <strong>tf.keras</strong> if we only have <strong>import tensorflow as tf</strong>? What's special about this import compared to the import in <strong>import math</strong>?</p>
  
  <p>Thanks</p>