【问题标题】:indexing list by tuples按元组索引列表
【发布时间】:2018-02-19 15:20:10
【问题描述】:
def greedy_decoder(input):
    flag = 0
    prob = 1
    ans_partial = np.zeros((1,maxlen_input))
    ans_partial[0, -1] = 2  #  the index of the symbol BOS (begin of sentence)
    for k in range(maxlen_input - 1):
        ye = model.predict([input, ans_partial])
        yel = ye[0,:]
        p = np.max(yel)
        mp = np.argmax(ye)

尝试运行此代码时会弹出此错误

yel = ye[0,:]
TypeError: list indices must be integers or slices, not tuple

知道如何解决这个问题吗?我正在使用 python 3.6 谢谢

【问题讨论】:

    标签: python python-3.x keras


    【解决方案1】:

    您不能对列表使用高级索引,但如果这样做,您的代码应该可以工作

    yel = ye[0]
    

    这实际上相当于实现高级索引的数组的当前行。

    【讨论】:

    • 我改变了它 ye[0] 但现在它给了我列表索引超出范围,知道这个错误的来源吗?
    猜你喜欢
    • 2022-09-27
    • 2013-10-30
    • 2021-10-29
    • 1970-01-01
    • 2016-05-26
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    相关资源
    最近更新 更多