diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index e3347f6886432..57ba1cf924b88 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -586,8 +586,7 @@ def transform(self, X, copy=True): raise ValueError("Input has n_features=%d while the model" " has been trained with n_features=%d" % ( n_features, expected_n_features)) - d = sp.lil_matrix((n_features, n_features)) - d.setdiag(self.idf_) + d = sp.dia_matrix((self.idf_, 0), shape=(n_features, n_features)) # *= doesn't work X = X * d