So, I have two numpy arrays, a
, of shape (p,2) and b
, of shape (q,2).
I create a KDTree with scipy
c=sp.KDTree(a)
I have an upper bound, ub=1.0/12.0
When I do
print c.query(b,distance_upper_bound=ub)
I get ([inf,inf,inf...],[len(a),len(a),len(a)...])
which means that a
and b
have no common elements.
To confirm this, I do a for loop
for n in range(len(c.data)):#the result is the same with len(a)
for m in range(len(b)):
if (c.data[m][0]-b[n][0])**2.0+(c.data[m][1]-b[n][1])**2.0<ub**2.0:
print c.data[m],b[n],n,m
Many n,m
pairs get printed.
I have made a
and b
arrays generic, because it has happened with different arrays.
The most mysterious thing to me is that in the same code, I have used query
and got good results.
So, could you point me in the right direction?
Edit: as requested,sample data. These are some data points printed by the for
cycle. The full arrays are really long.
a=np.array([[276.95368542701721, 330.18454774620238],
[276.95368542701721, 330.18454774620238],
[283.19923346114763, 337.60512985013065],
[270.32420807690886, 331.46587512659323],
[271.32525610216351, 333.51103014735435],
[271.9742523815284, 330.26777673087207],
[268.89584462538102, 331.5474437183201],
[278.6808380388178, 331.92691700030088],
[271.36541507290735, 332.74113908742231]])
b=np.array([[ 276.956177, 330.183134],
[ 276.956177, 330.183134],
[ 283.264282, 337.592966],
[ 270.319366, 331.538029],
[ 271.351807, 333.578056],
[ 272.019257, 330.268417],
[ 268.913958, 331.523153],
[ 278.681976, 331.927687],
[ 271.303917, 332.706767]])