pysal.lib.weights.w_union

pysal.lib.weights.w_union(w1, w2, silence_warnings=False)[source]

Returns a binary weights object, w, that includes all neighbor pairs that exist in either w1 or w2.

Parameters:
w1 : W

object

w2 : W

object

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