libpysal.weights.
w_intersection
(w1, w2, w_shape='w1', silence_warnings=False)[source]¶Returns a binary weights object, w, that includes only those neighbor pairs that exist in both w1 and w2.
Parameters: |
|
---|---|
Returns: |
|
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.
Examples
Construct rook weights matrices for two regions, one is 4x4 (16 areas) and the other is 6x4 (24 areas). An intersection of these two weights matrices results in the new weights matrix matching the smaller one.
>>> from libpysal.weights import lat2W
>>> w1 = lat2W(4,4)
>>> w2 = lat2W(6,4)
>>> import libpysal
>>> w = libpysal.weights.set_operations.w_intersection(w1, w2)
>>> w1[0] == w[0]
True
>>> w1.neighbors[15]
[11, 14]
>>> w2.neighbors[15]
[11, 14, 19]
>>> w.neighbors[15]
[11, 14]
>>>