SciPy sparse: optimize computation on non-zero elements of a sparse matrix (for tf-idf)
I'm making a fair few assumptions about the internal format that may not be justified, but this works on the demo data I tried:

factors = csr.shape[1] / (1 + np.diff(csr.indptr))
xs, ys = csr.nonzero()

csr.data = np.log(csr.data + 1.0) * np.log(factors[xs])


All I do is work on the internal dense data structure directly.