scipy.spatial ValueError: “x must consist of vectors of length %d but has shape %s”

淺唱寂寞╮ 提交于 2020-01-16 01:12:07

问题


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 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)))

I believe This is the source code.


回答1:


Figured it out:

This particular value error is referencing the length of the array used to build the KD Tree.

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.

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.

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.



来源:https://stackoverflow.com/questions/14264682/scipy-spatial-valueerror-x-must-consist-of-vectors-of-length-d-but-has-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!