[英]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.