pysal.lib.weights.block_weights

pysal.lib.weights.block_weights(regimes, ids=None, sparse=False)[源代码]

为政权邻国构建空间权重。

块邻接结构在基于体系成员身份定义邻居关系时是相关的。例如,在对美国所有县的分析中,属于同一州的所有县都可以定义为邻居。

参数:
regimes : 数组,数组

观测所属体制的ID

ids : 数组,数组

观测用ID的有序序列

稀疏的 : 布尔

if true返回wsp实例if false返回w实例

返回:
W : 空间权重实例

实例

>>> from pysal.lib.weights import lat2W
>>> import numpy as np
>>> regimes = np.ones(25)
>>> regimes[range(10,20)] = 2
>>> regimes[range(21,25)] = 3
>>> regimes
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 2., 2., 2., 2., 2., 2., 2.,
       2., 2., 2., 1., 3., 3., 3., 3.])
>>> w = block_weights(regimes)
>>> w.weights[0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
>>> w.neighbors[0]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 20]
>>> regimes = ['n','n','s','s','e','e','w','w','e']
>>> n = len(regimes)
>>> w = block_weights(regimes)
>>> w.neighbors == {0: [1], 1: [0], 2: [3], 3: [2], 4: [5, 8], 5: [4, 8], 6: [7], 7: [6], 8: [4, 5]}
True