scipy.interpolate.interpnd 抱怨'Delaunay'对象没有属性'simplices'



我正在清理几个月前写的一些代码,但由于某种原因,它不再工作了。。。简而言之,我使用scipy.interpolate.LinearNDInterpolator对象来插值模型并与数据进行比较。现在,当我试图用我想要插值的坐标调用插值器对象时,我得到了以下错误:

In [9]: a([[3500, 3.5, 1.5]])
AttributeError                            Traceback (most recent call last)
<ipython-input-9-91f2103e7a0c> in <module>()
----> 1 a([[3500, 3.5, 1.5]])
/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in     scipy.interpolate.interpnd.NDInterpolatorBase.__call__ (scipy/interpolate/interpnd.c:3133)()
/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in     scipy.interpolate.interpnd.LinearNDInterpolator._evaluate_double (scipy/interpolate/interpnd.c:3954)()
/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in scipy.interpolate.interpnd.LinearNDInterpolator._do_evaluate (scipy/interpolate/interpnd.c:4684)()
AttributeError: 'Delaunay' object has no attribute 'simplices'

我以前从未见过这个错误,代码以前也工作过。是不是有什么我不知道的事情改变了?

谢谢你的光临!

我猜您使用的是库的旧版本:

Delaunay库有两个不同的简化访问器:"Delaunay.simplices"one_answers"Delaunay顶点"显示在此处(最新文档):http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html

两个Delaunay.顶点中的顶点标记为"已弃用"。

然而,在Ubuntu 13.04上,simplices调用并不存在,因为它仍然使用scipy 0.11.0:http://docs.scipy.org/doc/scipy-0.11.0/reference/generated/scipy.spatial.Delaunay.html#scipy.spatial.Delaunay

试试这个最小的例子,或者只是重写你对顶点的简单调用:

from __future__ import print_function
import numpy as np
from scipy.spatial import Delaunay
import sys
my_molecule = np.random.rand(400,3) #points for query
points = np.random.rand(1000, 3)   #points used for Triangulation
diag = Delaunay(points)
simplices = diag.find_simplex(my_molecule)
for point,simplex in zip(my_molecule,simplices):
    if simplex == -1:
        print ("Point not included in diag.")
        continue
    print ("Doing vertices call: ")
    spoints = diag.vertices[simplex]
    print ("Doing simplices call: ")
    spoints = diag.simplices[simplex]

最新更新