给定坐标从(-x,-x,-x,...)到(+ y,+ y + y,...),x,y> 0的立方体,我如何得到所有的列表具有简短易读代码的整数?
到目前为止,我有:
list((x,y,z) for x in range(-x,y) for y in range(-x,y) for z in range(-x,y))
# has the dimension hardcoded
list(itertools.product(*[np.arange(-x, y)]*dim))
# difficult to understand what is going on
有更直观的解决方案吗?
你的第二个解决方案看起来非常好,不过我会这样做:
list(itertools.product(range(-x, y), repeat=dim))