Sep-14-2019, 06:42 PM
Can someone please tell what I am doing wrong??...I am continually getting an index error. I have a 4x2x3 matrix (lists) and I am trying to first create a list containing three lists and then as a final step I would like to reduce this to one list....I test lengths out in the command line so I do not understand why I am getting these index errors....
what would the solution look like in list comprehension?
thanks
what would the solution look like in list comprehension?
thanks
import random def m(): c = []; tmpa = []; tmpb = [] c.append([[[random.randint(0,4) for i in range(2)] for k in range(4)] for i in range(3)]) for i in range(2): tmpa = [] for j in range(4): tmpb = [] for k in range(2): p = sum(c[i][j][k]) tmpb.append(p) tmpb.append(tmpa) return(c)
Error:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/myPython/test.py", line 10, in m
p = sum(c[i][j][k])
IndexError: list index out of range