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

问题描述 投票:0回答:2

我正在尝试构建用于主题提取的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坐标?

python-3.x machine-learning coordinate-systems nmf
2个回答
0
投票

您可以用no_topics[0]选择第一个值

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


0
投票

您可以对numpy数组tfidf进行切片

topics = tfidf[0,:]
© www.soinside.com 2019 - 2024. All rights reserved.