Hi Conrad,
The array you have is length 1, and the first item is a numpy array (an
object) giving you the results you want.
So why do we use the weird dtype='object' thing?
Well, it's because when querying multiple points, each point does not
generally have the same number of neighbors within the given radius.
This means the results do not in general fit in a standard numpy data
array. KDTree in scipy goes the route of returning a very large data
array with lots of NaNs. This can cause unnecessary memory issues in
some cases. We decided to go the route of returning an array of
(different length) arrays: thus the dtype='object'. I agree it's
counter-intuitive at first, but I don't see any other good solution.
Perhaps the confusion is that you're querying only one point: in this
case the dtype=object is not strictly needed, but changing the behavior
for such special cases makes neighbors algorithms more awkward to use
within estimators: this is one of my complaints about the scipy KDTree.
Hope that helps,
Jake
On 11/21/2012 06:32 AM, Conrad Lee wrote:
Note that you could just say that I should stay away from using
BallTree and use NearestNeighbor instead. In particular I could use
the method NearestNeighbor.radius_neighbors instead of
BallTree.query_radius.
However, the output of NearestNeighbor.radius_neighbors is of the same
problematic type as BallTree.query_radius
On Wed, Nov 21, 2012 at 1:22 PM, Conrad Lee <[email protected]
<mailto:[email protected]>> wrote:
I'm having a hard time when using BallTree.query_radius.
Consider the following example:
points = np.random.random((10,3))
bt = BallTree(X)
idxs = bt.query_radius((0.0,0.0,0.0), r=1)
The strange thing is that idxs is of dtype "object". I thus can't
use it in the way I'd normally use it if it were an integer
array. I can't do idxs.ravel() to get a flat list of the
indices. idxs.shape returns (1,), which is awkward. If I run
`idxs.astype("u8") I get an error (ValueError: setting an array
element with a sequence.).
It's especially awkward because this is all different from the
index array I get when I run BallTree.query(...).
Is this behavior intended? Can it be improved? How can I convert
the array of dtype "object" into an integer array?
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general