A dense matrix explicitly stores every element, including zeros. In text processing, it makes all document–token counts visible, but wastes space when most entries are zero. section 3.2.1
Use a dense representation when:
- Inspecting a small matrix is more important than conserving memory. section 3.2.1
- The matrix contains many meaningful nonzero values rather than mostly empty placeholders. section 3.2.1
- Avoid converting large sparse data without checking scale, because the resulting array can exhaust available memory. section 3.2.1
Viewing count vectors as a dense NumPy array
After scikit-learn creates a 16-by-240 sparse count matrix, call `count_vectors.toarray()` to display every document–token count, including its many zeros. section 3.2.1
Listing 3.4 Using sklearn to compute word count vectors
>>> count_vectors.toarray() #1
array([[0, 0, 0, 0, 0, 0, 0, 1, ..., 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 2, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0],
...,
[0, 0, 0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, ..., 1, 0, 0, 0, 0, 1, 0, 0]])
Inspect the complete NumPy array produced from document word-count vectors. section 3.2.1
