SciPy

scipy.sparse.csr_matrix.prune

csr_matrix.prune()[source]

Remove empty space after all non-zero elements.