简体   繁体   English

IndexError:使用 numpy 的数组索引过多

[英]IndexError: too many indices for array using numpy

I have trouble in solving this problem.我在解决这个问题时遇到了麻烦。 I am using python numpy.我正在使用 python numpy。 And my goal is to print traffic light countdown.我的目标是打印红绿灯倒计时。

EDIT: So it's like in 1 intersection, there are 8 stoplights, and 3 timings(red,amber,green).编辑:所以就像在 1 个十字路口,有 8 个红绿灯和 3 个时间(红色、琥珀色、绿色)。 But my plus intersection consists of 4 intersection.但我的加号交叉点由 4 个交叉点组成。

8 stoplights mean straight road, north to south straight road, south to north straight road, east to west straight road, west to east 8个红绿灯表示直路、北向南直路、南向北直路、东向西直路、西向东

left turn, north to west left turn, west to north left turn, north to east left turn, east to south左转,从北到西 左转,从西到北 左转,从北到东 左转,从东到南

//edited
t = np.zeros((4, 8, 3)) //4 intersections, 8 stoplights, 3 timings

 for i in range(8):
   for j in range(4):
       t[j,i,0] = 10
       t[j,i,1] = 5
       t[j,i,2] = 10 

In the code stated above, it would give an error "Too many indices in array"在上述代码中,它会给出错误“数组中的索引过多”

t[j,i,0] = 10
t[j,i,1] = 5
t[j,i,2] = 10

Can somebody please tell me why and how to solve this.有人可以告诉我为什么以及如何解决这个问题。

If you want to create a 3 dimensional array, probably you should be doing:如果你想创建一个 3 维数组,你可能应该这样做:

t = np.zeros((4,8,3))

You are actually creating a single dimensional array of elements 4,8,3您实际上是在创建元素 4,8,3 的一维数组

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM