numpy.ndarray' object has no attribute 'query'

225 views
Skip to first unread message

vishalis...@gmail.com

unread,
Mar 23, 2016, 6:46:13 AM3/23/16
to pysal-dev
when i am running following code for weight generation :
import pysal
import numpy as np

x,y=np.indices((5,5))
x.shape=(25,1)
y.shape=(25,1)
data=np.hstack([x,y])

wknn3 = pysal.knnW(data, k = 3)
wknn3.neighbors[0]
wknn3.s0

then i am getting following error:

Traceback (most recent call last):
  File "C:\Python27\FOSS4G NA 2015 - Spatial Data Analysis in Python\PySAL_Workshop\mine\knnweight.py", line 9, in <module>
    wknn3 = pysal.knnW(data, k = 3)
  File "C:\Python27\FOSS4G NA 2015 - Spatial Data Analysis in Python\PySAL_Workshop\mine\pysal\weights\Distance.py", line 86, in knnW
    nnq = kdtree.query(data, k=k+1, p=p)
AttributeError: 'numpy.ndarray' object has no attribute 'query'

why? please help.

Levi John Wolf

unread,
Mar 23, 2016, 12:43:39 PM3/23/16
to pysal-dev
Hello! Thank you for submitting this issue!

I've gone ahead and filed it on our project issue tracker on github.

It appears that the error actually occurs right at the point where weights are constructed.


To get this to work immediately, see if replacing:

wknn3 = pysal.knnW(data, k=3)

with

kdt = pysal.cg.kdtree.KDTree(data)
wknn3 = pysal.knnW(kdt, k=3)

works for you?

--

---
You received this message because you are subscribed to the Google Groups "pysal-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pysal-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
​​
Levi John Wolf
GeoDa Center for Geospatial Analysis & Computation
Arizona State University | Ph.D. Student
levijohnwolf.com

vishalis...@gmail.com

unread,
Mar 24, 2016, 4:43:21 AM3/24/16
to pysal-dev
it is working thank you dear...
Reply all
Reply to author
Forward
0 new messages