简体   繁体   English

如何修复“类型错误:列表索引必须是整数或切片,而不是元组”

[英]How to fix "TypeError: list indices must be integers or slices, not tuple"

     12         for ii, (x, y) in enumerate(get_batches(train_x, train_y, batch_size), 1):
     13             feed = {inputs_: x,
---> 14                     labels_: y[:, None],
     15                     keep_prob: 0.5,
     16                     initial_state: state}

TypeError: list indices must be integers or slices, not tuple

As the error message states, y is a list.正如错误消息所述, y是一个列表。 So you cannot have two values in the brackets.所以括号中不能有两个值。 That is how numpy arrays work.这就是 numpy 数组的工作原理。 You should probably change your code to the following:您可能应该将代码更改为以下内容:

feed = {inputs_: x,
        labels_: np.array(y)[:, None],
        keep_prob: 0.5,
        initial_state: state}

thanks but this method did not solve the problem.谢谢,但是这个方法没有解决问题。 I found the solution when the problem is done as follows.问题解决后,我找到了解决方案,如下所示。

        y = np.array(y)
        feed = {inputs_: x,
                labels_: y[:, None],
                keep_prob: 0.5,
                initial_state: state}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:列表索引必须是整数或切片,而不是元组? - TypeError: list indices must be integers or slices, not tuple? TypeError:列表索引必须是整数或切片,而不是元组 - TypeError: list indices must be integers or slices, not tuple “TypeError: list indices must be integers or slices, not tuple”——如何解决 - “TypeError: list indices must be integers or slices, not tuple”- how to solve 如何修复错误“元组索引必须是整数或切片,而不是列表” - how to fix error "tuple indices must be integers or slices, not list" 如何修复此错误:列表索引必须是整数或切片,而不是元组 - How to fix this error: list indices must be integers or slices, not tuple 如何修复“TypeError: list indices must be integers or slices, not str.”? - How to fix " TypeError: list indices must be integers or slices, not str. "? 列表类型错误:列表索引必须是整数或切片,而不是元组 - List of lists TypeError: list indices must be integers or slices, not tuple TypeError:列表索引必须是整数或切片,而不是元组列表的元组 - TypeError: list indices must be integers or slices, not tuple for list of tuples 类型错误:列表索引必须是整数或切片,而不是在 python 中使用 sys 导入的元组 - TypeError: list indices must be integers or slices, not tuple with sys import in python 新编码器:TypeError:列表索引必须是整数或切片,而不是元组 - New coder: TypeError: list indices must be integers or slices, not tuple
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM