I am writing code to find out if a point 'npA' from the set 'pA' has a closest neighbour from a set 'pB' containing randomly generated points. (In the code I have a single point but in my application, the points would be randomly generated). My problem is that I am unable to view/access the resulting list from the cKDTree.query_ball_point
result.
In my variable explorer the result displays the type as object
and the value as ndarray object of numpy module
. When I try to view/access this list i.e. result
, a window pops up that says object arrays are currently not supported
. I would like to know how I can view this list or convert it to an array that I can use for some analysis later on.
from scipy.spatial import cKDTree
import numpy as np
pA = np.array([[0.000,0.000],[0.300,0.000],[0.600,0.000],[0.000,0.300], [0.300,0.300],[0.600,0.300],[0.000,0.600],[0.300,0.600],[0.600,0.600]])
pB = np.array([[0.300,0.600]])
npA =[[pA[0,0],pA[0,1]]]
npA = np.array(npA)
tree = cKDTree(npA)
result = tree.query_ball_point(pB,0.100) #I wish to view the list stored in result
I'm not sure if I understood your problem correctly, but just writing:
print(result)
and running your code from the command line gives: [list([])], and changing the value of distance from 0.1 (no points so close) to 1.0 gives [list([0L])], where 0 is the position of the nearest neighbour in your list.
BTW, the construction of the array npA seems strange to me. You could get the same result just writing: [pA[0]]
.