libpysal.weights.w_union¶
- libpysal.weights.w_union(w1, w2, **kwargs)[source]¶
Returns a binary weights object, w, that includes all neighbor pairs that exist in either w1 or w2.
- Parameters:
- Returns:
- w
W
object
- w
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0. Returns a matrix with all the unique IDs from w1 and w2.
Examples
Construct rook weights matrices for two regions, one is 4x4 (16 areas) and the other is 6x4 (24 areas). A union of these two weights matrices results in the new weights matrix matching the larger one.
>>> from libpysal.weights import lat2W, w_union >>> w1 = lat2W(4,4) >>> w2 = lat2W(6,4) >>> w = w_union(w1, w2) >>> w1[0] == w[0] True >>> w1.neighbors[15] [11, 14] >>> w2.neighbors[15] [11, 14, 19] >>> w.neighbors[15] [19, 11, 14]