python - itertools.product 的更快替代品

标签 python arrays numpy scipy python-itertools

有没有比 itertools.product 更快的方法来获取 x、y、z 的所有坐标组合?例如,我的范围是:x:10-310,y:10-310 和 z:0-65。

编辑

例如,我必须将所有坐标放在一个多数据中,如下所示:

points1 = vtk.vtkPoints()                      
for coords in itertools.product(x1,y1,z1):
   points1.InsertNextPoint(coords)
boxPolyData1 = vtk.vtkPolyData()
boxPolyData1.SetPoints(points1)

最佳答案

使用np.mgrid :

import numpy as np

x, y, z = np.mgrid[10:311, 10:311, 0:66]

我假设您想要端点 31065(含)。

关于python - itertools.product 的更快替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574827/

相关文章:

javascript - 正则表达式捕获尽可能多的 Javascript 重定向

python - 重建具有设定长度的列表

python:从列表中输出数据

php - 检查数组元素是否对称

python - 使用 numpy 数组中的索引执行计算和比较

python - 分箱后如何对数字列表的内容进行配对

Python 多处理作业到 Celery 任务但 AttributeError

arrays - 从单例创建一个通用数组

javascript - 从javascript中的数组中查找中值(8个值或9个值)

python - pandas 根据另一列获取 True 值的(开始、结束)位置