如何使用Python提取点的x坐标

时间:2019-12-26 05:17:42

标签: python-3.x machine-learning coordinate-systems nmf

我正在尝试构建用于主题提取的NMF模型。为了重新训练模型,我必须将一个参数传递给nmf函数,为此我需要传递算法返回的给定点的x坐标,这是供参考的代码:

no_features = 1000
no_topics = 9
print ('Old number of topics: ', no_topics)
tfidf_vectorizer = TfidfVectorizer(max_df = 0.95, min_df = 2, max_features = no_features, stop_words = 'english')
tfidf = tfidf_vectorizer.fit_transform(documents)
tfidf_feature_names = tfidf_vectorizer.get_feature_names()

no_topics = tfidf.shape
print('New number of topics :', no_topics)
# nmf = NMF(n_components = no_topics, random_state = 1, alpha = .1, l1_ratio = .5, init = 'nndsvd').fit(tfidf)

在第三行上,tfidf.shape返回变量(no_topics)的点(3,1000),但是我希望将该变量设置为仅x坐标,即(3)。 如何仅从该点提取x坐标?

2 个答案:

答案 0 :(得分:1)

您可以使用no_topics[0]

选择第一个值

print('New number of topics : {}'.format(no_topics[0]))

答案 1 :(得分:1)

您可以使用

对numpy数组tfidf进行切片
topics = tfidf[0,:]