pysal.lib.weights.
w_difference
(w1, w2, w_shape='w1', constrained=True, silence_warnings=False)[source]¶Returns a binary weights object, w, that includes only neighbor pairs in w1 that are not in w2. The w_shape and constrained parameters determine which pairs in w1 that are not in w2 are returned.
Parameters: |
|
---|---|
Returns: |
|
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.
Examples
Construct rook (w2) and queen (w1) weights matrices for two 4x4 regions (16 areas). A queen matrix has all the joins a rook matrix does plus joins between areas that share a corner. The new matrix formed by the difference of rook from queen contains only join at corners (typically called a bishop matrix). Note that the difference of queen from rook would result in a weights matrix with no joins.
>>> from pysal.lib.weights import lat2W
>>> w1 = lat2W(4,4,rook=False)
>>> w2 = lat2W(4,4,rook=True)
>>> import pysal.lib
>>> w = pysal.lib.weights.set_operations.w_difference(w1, w2, constrained=False)
>>> w1[0] == w[0]
False
>>> w1.neighbors[15]
[10, 11, 14]
>>> w2.neighbors[15]
[11, 14]
>>> w.neighbors[15]
[10]
>>>