scipy.spatial ValueError:“x 必须由长度为 %d 但形状为 %s 的向量组成" [英] scipy.spatial ValueError: "x must consist of vectors of length %d but has shape %s"
问题描述
Scipy 拥有出色的 空间分析 包,其中包括一棵 K 维树.我正在尝试使用查询功能,它返回此错误:
Scipy has an excelent spatial analysis pack which includes a K-dimensional tree. I am attempting to use the query function and it is returning this error:
ValueError: x 必须由长度为 6 的向量组成,但具有形状 (2,)
ValueError: x must consist of vectors of length 6 but has shape (2,)
有人知道这个错误指的是什么吗?
Does anyone know what this error is referring to?
从一些谷歌搜索我发现它有这种通用格式:
From some google searching I have discovered it has this general format:
raise ValueError("x must consist of vectors of length %d but has shape %s" % (self.m, np.shape(x)))
我相信这个是源代码.
推荐答案
想通了:
这个特定的值错误引用了用于构建 KD 树的数组的长度.
This particular value error is referencing the length of the array used to build the KD Tree.
%d
值表示用于构建 KD 树的数组的长度,%s
值表示您正在使用的类似数组的对象的长度查询.
The %d
value represents the length of the array used to build the KD tree, and the %s
value represents the length of the array like object you are using to query.
在我的示例中,%d
值为 6,因为我构建了一个 6 维数组.%s
的值是 2,因为我只给它提供了两个坐标:(X,Y)
来查询.
In my example the %d
value was 6 because I had built a 6 dimensional array.
The %s
value was 2 because I had only fed it two coordinates: (X,Y)
to query.
我的错误是我在构建 KD 树时不小心包含了 4 个额外的字段.现在两个值都是 2,一切都按预期工作.
My error was that I had accidentally included 4 extra fields when building the KD tree. Now that both values are 2, all works as expected.
这篇关于scipy.spatial ValueError:“x 必须由长度为 %d 但形状为 %s 的向量组成"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!