我正在将Matlab代码转换为python.Matlab中遇到了一个函数'voronoin',该函数提供顶点和单元格数组作为输出。从我的程序中,我只会得到顶点。我从程序中获得的单元阵列与在Matlab中获得的单元阵列不匹配。
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi
def voronoi_volumes(points):
v = Voronoi(points)
print(v.vertices)
for i, reg_num in enumerate(v.point_region):
print(reg_num)
indices = v.regions[reg_num]
print(indices)
points = np.array([[ 0.4074, 0.4567],
[ 0.4529, 0.3162],
[ 0.0635, 0.0488],
[ 5, -45],
[ 5, 55],
[-45, 5],
[ 55, 5]])
k = voronoi_volumes(points)
在Matlab中,我的输出是:
[9,5,3,4,7]
[9,7,6,8]
[7,4,2,6]
[8,1,2,6]
[5,1,3]
[4,2,1,3]
[9,5,1,8]
在python中,我得到的输出是:
[7, 3, 1, 2, 5]
[7, 5, 4, 6]
[5, 2, 0, 4]
[6, -1, 0, 4]
[-1, 1, 3]
[-1, 0, 2, 1]
[7, 3, -1, 6]
答案 0 :(得分:0)
iam进入python的答案是正确的.Matlab和python具有不同的索引。当我尝试从索引访问顶点时,会从两个索引中获得相同的答案。