libpysal.weights.w_intersection¶

libpysal.weights.
w_intersection
(w1, w2, w_shape='w1', **kwargs)[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
str
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.
 **kwargs
keyword
arguments
optional arguments for
pysal.weights.W
 w1
 Returns
 w
W
object
 w
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, w_intersection >>> w1 = lat2W(4,4) >>> w2 = lat2W(6,4) >>> w = 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]