I have a bunch of coordinates contained in three `numpy` arrays: `xarr`, `yarr` and `zarr` (corresponding positions in each array belong to the same point - i.e the first point is at `xarr[0]`, `yarr[0]`, `zarr[0]`). Given another point in space at `P(x,y,z)` I would like to find all the points that are within a distance *r* of `P(x,y,z)`. 

My current (and very inefficient) method of doing this is to simply iterate through and calculate the distance to each point and see if it is within *r* of `P(x,y,z)`. 

However, I'd like to use SciPy's k-d tree algorithm to do this, but I'm not really sure how to start implementing it (I'm very new to Python). I'd really appreciate it if someone could briefly outline some code that demonstrates *how to set up* a k-d tree given data in the format I've got.

I know of [SciPy documentation of its k-d tree implementation](http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.KDTree.html#scipy.spatial.KDTree), 
I've looked over it but I'm still confused on how to create the tree given the data in the format I have (`np.mgrid` and `ravel()` were called and I don't quite understand why).

Thanks!