pysal.lib.weights.w_intersection

pysal.lib.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:
w1 : W

object

w2 : W

object

w_shape : string

Defines the shape of the returned weights matrix. ‘w1’ returns a matrix with the same IDs as w1; ‘all’ returns a matrix with all the unique IDs from w1 and w2; and ‘min’ returns a matrix with only the IDs occurring in both w1 and w2.

silence_warnings : boolean

Switch to turn off (default on) print statements for every observation with islands

Returns:
w : W

object

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 pysal.lib.weights import lat2W
>>> w1 = lat2W(4,4)
>>> w2 = lat2W(6,4)
>>> import pysal.lib
>>> w = pysal.lib.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]
>>>