scipy.spatial ValueError: “x must consist of vecto

2019-07-26 09:58发布

问题:

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.