运行scipy插值时出现分段错误

问题描述 投票:1回答:1

运行以下代码:

from scipy.interpolate import LinearNDInterpolator
import numpy as np


pts = np.column_stack([np.array([1,2,3]),np.array([2,3,4])])
z = np.array([6,7,8])
interp = LinearNDInterpolator(pts, z, fill_value= np.nan)

在我的计算机上产生输出

分段错误:11

为了修复它,我最近卸载并重新安装了numpy和scipy,这样

scipy。version1.3.3numpy。版本'1.17.4'

但没有运气

python scipy
1个回答
1
投票

这不一定是答案,而只是更多信息,当我执行确切的代码时,我将其作为错误的颜色全部输出:

Traceback (most recent call last):
  File "/Users/tadhgmcdonald-jensen/Documents/test.py", line 8, in <module>
    interp = LinearNDInterpolator(pts, z, fill_value= np.nan)
  File "interpnd.pyx", line 248, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__
  File "qhull.pyx", line 1833, in scipy.spatial.qhull.Delaunay.__init__
  File "qhull.pyx", line 355, in scipy.spatial.qhull._Qhull.__init__
scipy.spatial.qhull.QhullError: QH6154 Qhull precision error: Initial simplex is flat (facet 1 is coplanar with the interior point)

While executing:  | qhull d Q12 Qbb Qc Qt Qz
Options selected for Qhull 2015.2.r 2016/01/18:
  run-id 923456758  delaunay  Q12-no-wide-dup  Qbbound-last  Qcoplanar-keep
  Qtriangulate  Qz-infinity-point  _pre-merge  _zero-centrum  Qinterior-keep
  Pgood  _max-width  2  Error-roundoff 5.5e-15  _one-merge 3.9e-14
  Visible-distance 1.1e-14  U-coplanar-distance 1.1e-14  Width-outside 2.2e-14
  _wide-facet 6.7e-14

precision problems (corrected unless 'Q0' or an error)
      2 flipped facets

The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.

Qhull could not construct a clearly convex simplex from points:
- p1(v3):     2     3  0.71
- p3(v2):     2     3     2
- p2(v1):     3     4   1.8
- p0(v0):     1     2 5.6e-17

The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet.  The maximum round off error for
computing distances is 5.5e-15.  The center point, facets and distances
to the center point are as follows:

center point        2        3    1.122

facet p3 p2 p0 distance=    0
facet p1 p2 p0 distance=    0
facet p1 p3 p0 distance=    0
facet p1 p3 p2 distance=    0

These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates.  Trial points
are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are:
  0:         1         3  difference=    2
  1:         2         4  difference=    2
  2:  5.551e-17         2  difference=    2

If the input should be full dimensional, you have several options that
may determine an initial simplex:
  - use 'QJ'  to joggle the input and make it full dimensional
  - use 'QbB' to scale the points to the unit cube
  - use 'QR0' to randomly rotate the input for different maximum points
  - use 'Qs'  to search all points for the initial simplex
  - use 'En'  to specify a maximum roundoff error less than 5.5e-15.
  - trace execution with 'T3' to see the determinant for each point.

If the input is lower dimensional:
  - use 'QJ' to joggle the input and make it full dimensional
  - use 'Qbk:0Bk:0' to delete coordinate k from the input.  You should
    pick the coordinate with the least range.  The hull will have the
    correct topology.
  - determine the flat containing the points, rotate the points
    into a coordinate plane, and delete the other coordinates.
  - add one or more points to make the input full dimensional.

我对scipy不太了解,无法确切了解发生了什么,但是您的输入是否有可能是无效的,而您恰巧没有在计算机上获得有意义的输出?这可能与向scipy报告错误有关。

scipy.version.version == '1.3.1' and numpy.version.version == '1.17.3'


0
投票

正如其他答案中的错误消息所述:您的3个点没有形成三角形:

y
^
4       p4
3    p2
2 p1
1
0  1  2  3  > x

他们在一条线上。简单是通用的n维“三角形”的名称,您的2D点应该形成一个实际的三角形。

热门问题
推荐问题
最新问题