Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays gettinf错误';元组';对象没有属性';拆分';_Arrays_Python 3.x_List_Lda - Fatal编程技术网

Arrays gettinf错误';元组';对象没有属性';拆分';

Arrays gettinf错误';元组';对象没有属性';拆分';,arrays,python-3.x,list,lda,Arrays,Python 3.x,List,Lda,我尝试使用lda获取主题。但是在这段代码中,当我尝试将具有类似单词的主题分组在一起时,我会遇到此错误。 对于l.split(“+”)中的t: AttributeError:“tuple”对象没有属性“split”您只能拆分字符串 试一试 否则,不要使用元组 def generateTopics(corpus, dictionary): # Build LDA model using the above corpus lda = models.ldamodel.LdaModel(c

我尝试使用lda获取主题。但是在这段代码中,当我尝试将具有类似单词的主题分组在一起时,我会遇到此错误。 对于l.split(“+”)中的t:
AttributeError:“tuple”对象没有属性“split”

您只能拆分字符串

试一试

否则,不要使用元组

def generateTopics(corpus, dictionary):
    # Build LDA model using the above corpus
    lda = models.ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50)
    corpus_lda = lda[corpus]

    # Group topics with similar words together.
    tops = set(lda.show_topics(50))
    top_clusters = []
    for l in tops:
        top = []
    for t in l.split(" + "):
        top.append((t.split("*")[0], t.split("*")[1]))
    top_clusters.append(top)
str(l).split(" + ")