【发布时间】:2020-12-10 17:48:31
【问题描述】:
我想在一个 numpy 数组中创建特定的对,并用一个简单的打印函数展示我想要的东西。我有两个数组:
points=np.arange(1,15)
然后我有另一个数组:
repetition= np.array([4, 4, 2, 2, 1, 1])
现在,我想打印以下对(我刚刚写了评论以显示我想要的):
1 5 # first value of points and (1+4)th value of point
2 6 # second value of points and (2+4)th value of point
3 7 # third value of points and (3+4)th value of point
4 8 # fourth value of points and (3+4)th value of point
7 9 # seventh value of points and (6+2)th value of point
8 10 # eighth value of points and (8+2)th value of point
9 11 # ninth value of points and (9+2)th value of point
10 12 # tenth value of points and (10+2)th value of point
12 13 # twelfth value of points and (11+2)th value of point
13 14 # thirteenth value of points and (13+1)th value of point
我尝试了以下代码,但它没有给我预期的结果:
for m, n in zip (points, repetition):
print (m, m+n)
在图中,我可视化了我的问题,其中红线显示了我的配对。我非常感谢您提前提供的任何帮助。
【问题讨论】:
-
我一直在思考这个问题;出于好奇,应用程序是什么?
-
我有几点意见。我正在连接这些点以创建线条。然后,我想使用我在该步骤中再次卡住的这些线创建表面:-(。我想在 Python 包中创建表面。
-
哦,我明白了。我想您对Delaunay triangulation 很熟悉?顺便说一句,Matplotlib 可以选择在其
Triangulation类中为您使用该算法。 (记忆通道:我记得,早在九十年代初,在 C 中实现非常快的 Delaunay(和 Voronoi)。 -
我对 Delaunay 三角剖分有一点了解,但我使用的是一个名为 gmsh [gmsh.info/] 的 Python 包,它为我创建了网格。我只需要将点导入其中。然后,通过给出点数(您的解决方案正在为我这样做),它会创建线条。然后我需要连接线来创建曲面,最后根据曲面制作网格。