Pythonic way of iterating over 3D array

前端 未结 2 1026
庸人自扰
庸人自扰 2020-12-14 13:12

I have a 3D array in Python and I need to iterate over all the cubes in the array. That is, for all (x,y,z) in the array\'s dimensions I need to access the cub

2条回答
  •  借酒劲吻你
    2020-12-14 13:39

    import itertools
    for x, y, z in itertools.product(xrange(x_size), 
                                     xrange(y_size), 
                                     xrange(z_size)):
        work_with_cube(array[x, y, z])
    

提交回复
热议问题