当前位置:  开发笔记 > 编程语言 > 正文

如何使用python获取n维立方体中所有整数点的列表?

如何解决《如何使用python获取n维立方体中所有整数点的列表?》经验,为你挑选了1个好方法。

给定坐标从(-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

有更直观的解决方案吗?



1> Stefan Pochm..:

你的第二个解决方案看起来非常好,不过我会这样做:

list(itertools.product(range(-x, y), repeat=dim))

推荐阅读
保佑欣疼你的芯疼
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有