user13446466
user13446466

Reputation:

IndexError: too many indices for array using numpy

I have trouble in solving this problem. I am using 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). But my plus intersection consists of 4 intersection.

8 stoplights mean straight road, north to south straight road, south to north straight road, east to west straight road, west to east

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.

Upvotes: 0

Views: 52

Answers (1)

Jay
Jay

Reputation: 24905

If you want to create a 3 dimensional array, probably you should be doing:

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

You are actually creating a single dimensional array of elements 4,8,3

Upvotes: 0

Related Questions