Skip to content
AI360Xpert
Glossary
Definition

Sparse Matrix

A matrix stored as only its non-zero entries, because almost all of its cells are zero.

CSR format keeps three arrays: the values, their column indices, and a pointer marking where each row starts. A row of 50,000 zeros then costs almost nothing, which is what makes one-hot blocks, document-term matrices and user-item tables workable at all.

The arithmetic decides whether a job runs. A 1,000,000×50,0001{,}000{,}000 \times 50{,}000 matrix has 5×10105 \times 10^{10} cells, so 400GB dense at 8 bytes each. At 0.1% density the same data is roughly 600MB in CSR.

Three ordinary operations destroy that and each is a common way to run out of memory: .toarray(), subtracting a column mean, and imputing the zeros. The first two have one-argument fixes, and the third is usually a mistake — a structural zero means "not this category" rather than a missing value.