def transform(self, X, copy=True):
    '\n        Parameters\n        ----------\n        X : sparse matrix, [n_samples, n_features] document-term matrix\n        copy : boolean, optional (default=True)\n        '
    if (hasattr(X, 'dtype') and np.issubdtype(X.dtype, np.float)):
        X = sp.sparse.csr_matrix(X, copy=copy)
    else:
        X = sp.sparse.csr_matrix(X, dtype=np.float, copy=copy)
    (n_samples, n_features) = X.shape
    doc_len = X.sum(axis=1)
    sz = (X.indptr[1:] - X.indptr[0:(- 1)])
    rep = np.repeat(np.asarray(doc_len), sz)
    nom = (self.k1 + 1)
    denom = (X.data + (self.k1 * ((1 - self.b) + ((self.b * rep) / self._average_document_len))))
    data = ((X.data * nom) / denom)
    X = sp.sparse.csr_matrix((data, X.indices, X.indptr), shape=X.shape)
    if self.use_idf:
        check_is_fitted(self, '_idf_diag', 'idf vector is not fitted')
        expected_n_features = self._idf_diag.shape[0]
        if (n_features != expected_n_features):
            raise ValueError(('Input has n_features=%d while the model has been trained with n_features=%d' % (n_features, expected_n_features)))
        X = (X * self._idf_diag)
    return X
Parameters
----------
X : sparse matrix, [n_samples, n_features] document-term matrix
copy : boolean, optional (default=True)
def transform(self, X, copy=True):
    '\n        Parameters\n        ----------\n        X : sparse matrix, [n_samples, n_features] document-term matrix\n        copy : boolean, optional (default=True)\n        '
    if (hasattr(X, 'dtype') and np.issubdtype(X.dtype, np.float)):
        X = sp.sparse.csr_matrix(X, copy=copy)
    else:
        X = sp.sparse.csr_matrix(X, dtype=np.float, copy=copy)
    (n_samples, n_features) = X.shape
    doc_len = X.sum(axis=1)
    sz = (X.indptr[1:] - X.indptr[0:(- 1)])
    rep = np.repeat(np.asarray(doc_len), sz)
    nom = (self.k1 + 1)
    denom = (X.data + (self.k1 * ((1 - self.b) + ((self.b * rep) / self._average_document_len))))
    data = ((X.data * nom) / denom)
    X = sp.sparse.csr_matrix((data, X.indices, X.indptr), shape=X.shape)
    if self.use_idf:
        check_is_fitted(self, '_idf_diag', 'idf vector is not fitted')
        expected_n_features = self._idf_diag.shape[0]
        if (n_features != expected_n_features):
            raise ValueError(('Input has n_features=%d while the model has been trained with n_features=%d' % (n_features, expected_n_features)))
        X = (X * self._idf_diag)
    return X