Data Science, Machine Learning.
vect = CountVectorizer(stop_words=stopwords) # this can be done with less memory overhead by using a generator vocabulary = vect.fit(a + b).vocabulary_ tfidf_vect = TfidfVectorizer(stop_words=stopwords, vocabulary=vocabulary) a_mat = tfidf_vect.fit_transform(a) b_mat = tfidf_vect.fit_transform(b)