我正试图掌握pysal。假设我有一个这样创建的棋盘:
import numpy as np
import pysal
def build_checkerboard(w, h) :
re = np.r_[ w*[0,1] ] # even-numbered rows
ro = np.r_[ w*[1,0] ] # odd-numbered rows
return np.row_stack(h*(re, ro))
cb = build_checkerboard(5, 5)
现在我删除最后一行和最后一列以匹配权重矩阵中可用的维度pysal
:
cb = np.delete(cb, (9), axis=0)
cb = np.delete(cb, (9), axis=1)
In[1]: cb
Out[1]:
array
([[0, 1, 0, 1, 0, 1, 0, 1, 0],
[1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0],
[1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0],
[1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0],
[1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0]])
现在让我们使用Queen 邻接规则(又名Moore 邻域)来使用 Join Count Statistics(我的值cb
是0
or ):1
w=pysal.lat2W(3,3, rook=False) #This yields a 9x9 matrix
jc=pysal.Join_Counts(cb,w) #The Join Counts
现在,结果:
In[2]: jc.bb #The 1-to-1 joins
Out[2]: array([ 4., 4., 4., 4., 4., 4., 4., 4., 4.])
In[3]: jc.bw #The 1-to-0 joins
Out[3]: array([ 12., 12., 12., 12., 12., 12., 12., 12., 12.])
In[4]: jc.ww #The 0-to-0 joins
Out[5]: array([ 4., 4., 4., 4., 4., 4., 4., 4., 4.])
In[5]: jc.J #The total number of joins
Out[5]: 20.0
我的问题:
- 为什么我没有得到不同连接的单个值,而是一个数组?此外,数组的每个值似乎都指向一个矩阵单元,但我没有得到总和。
20.0
就连接总数而言,是4+4+12
。考虑到矩阵的大小和结构,我预计会有更多的连接(更改)。为什么我得到的数字与预期的相差甚远?