title: how to calculate term-document matrix?
body: <p>I know that Term-Document Matrix is a mathematical matrix that describes the frequency of terms that occur in a collection of documents. In a document-term matrix, rows correspond to documents in the collection and columns correspond to terms.</p>
  
  <p>I am using <em>sklearn's CountVectorizer</em> to extract features from strings( text file ) to ease my task. The following code returns a term-document matrix according to the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html" rel="nofollow noreferrer">sklearn_documentation</a></p>
  
  <pre><code>from sklearn.feature_extraction.text import CountVectorizer
  import numpy as np
  vectorizer = CountVectorizer(min_df=1)
  print(vectorizer)
  content = ["how to format my hard disk", "hard disk format problems"]
  X = vectorizer.fit_transform(content) #X is Term-document matrix
  print(X)
  </code></pre>
  
  <p>The output is as follows <br/> <a href="https://i.stack.imgur.com/cwabV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cwabV.png" alt="Output"></a>  <br/> I am not getting how this matrix has been calculated.please discuss the example shown in the code.  I have read one more example from the <a href="https://en.wikipedia.org/wiki/Document-term_matrix#General_Concept" rel="nofollow noreferrer">Wikipedia</a> but could not understand.</p>