title: Term document matrix and cosine similarity in Python
body: <p>I have following situation that I want to address using <code>Python</code> (preferably using <code>numpy</code> and <code>scipy</code>):</p>
  
  <ol>
  <li>Collection of documents that I want to convert to a sparse term document matrix.</li>
  <li>Extract sparse vector representation of each document (i.e. a row in the matrix) and find out top 10 similary documents using cosine similarity within certain subset of documents (documents are labelled with categories and I want to find similar documents within the same category).</li>
  </ol>
  
  <p>How do I achieve this in <code>Python</code>? I know I can use <code>scipy.sparse.coo_matrix</code> to represent documents as sparse vectors and take dot product to find cosine similarity, but how do I convert the entire corpus to a large but sparse term document matrix (so that I can also extract it's rows as <code>scipy.sparse.coo_matrix</code> row vectors)?</p>
  
  <p>Thanks.</p>