def count ( self , X ) : # Sum on axis 0 (by columns), each column is a word # Convert the matrix to an array # Squeeze to remove the 1 dimension objects (like ravel) return np . squeeze ( np . asarray ( X . sum ( axis = 0 ) ) )
python how to select the most relevant words of a sparse document term matrix
Called from the fit method this method gets all the words from the corpus and their corresponding frequency counts .
def count(self, X):
        """
        Called from the fit method, this method gets all the
        words from the corpus and their corresponding frequency
        counts.

        Parameters
        ----------

        X : ndarray or masked ndarray
            Pass in the matrix of vectorized documents, can be masked in
            order to sum the word frequencies for only a subset of documents.

        Returns
        -------

        counts : array
            A vector containing the counts of all words in X (columns)

        """
        # Sum on axis 0 (by columns), each column is a word
        # Convert the matrix to an array
        # Squeeze to remove the 1 dimension objects (like ravel)
        return np.squeeze(np.asarray(X.sum(axis=0)))