def corpus2dense(corpus, num_terms, num_docs=None, dtype=np.float32):
 if (num_docs is not None):
  (docno, result) = ((-1), np.empty((num_terms, num_docs), dtype=dtype))
  for (docno, doc) in enumerate(corpus):
   result[:, docno] = sparse2full(doc, num_terms)
  assert ((docno + 1) == num_docs)
 else:
  result = np.column_stack((sparse2full(doc, num_terms) for doc in corpus))
 return result.astype(dtype)

def corpus2dense ( corpus , num_terms , num_docs = None , dtype = np . float32 ) : if ( num_docs is not None ) : ( docno , result ) = ( ( - 1 ) , np . empty ( ( num_terms , num_docs ) , dtype = dtype ) ) for ( docno , doc ) in enumerate ( corpus ) : result [ : , docno ] = sparse2full ( doc , num_terms ) assert ( ( docno + 1 ) == num_docs ) else : result = np . column_stack ( ( sparse2full ( doc , num_terms ) for doc in corpus ) ) return result . astype ( dtype )
convert corpus into a dense np array .