The weights.user module provides for set operations on weights objects .. versionadded:: 1.0
Set-like manipulation of weights matrices.
Returns a binary weights object, w, that includes only neighbor pairs in w1 that are not in w2. The w_shape and constrained parameters determine which pairs in w1 that are not in w2 are returned.
| Parameters: | w1 : W object w2 : W object w_shape : string
constrained : boolean
|
|---|---|
| Returns: | w : W object |
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.
Examples
>>> import pysal
>>> w1 = pysal.lat2W(4,4,rook=False)
>>> w2 = pysal.lat2W(4,4,rook=True)
>>> w = w_difference(w1, w2, constrained=False)
>>> w1[0] == w[0]
False
>>> w1.neighbors[15]
[10, 11, 14]
>>> w2.neighbors[15]
[11, 14]
>>> w.neighbors[15]
[10]
>>>
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
|
|---|---|
| Returns: | w : W object |
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.
Examples
>>> import pysal
>>> w1 = pysal.lat2W(4,4)
>>> w2 = pysal.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]
>>>
Returns a binary weights object, w, that includes only those observations in ids.
| Parameters: | w1 : W object ids : list
|
|---|---|
| Returns: | w : W object |
Examples
>>> import pysal
>>> w1 = pysal.lat2W(6,4)
>>> ids = range(16)
>>> w = w_subset(w1, ids)
>>> w1[0] == w[0]
True
>>> w1.neighbors[15]
[11, 14, 19]
>>> w.neighbors[15]
[11, 14]
>>>
Returns a binary weights object, w, that includes only neighbor pairs that are not shared by w1 and w2. The w_shape and constrained parameters determine which pairs that are not shared by w1 and w2 are returned.
| Parameters: | w1 : W object w2 : W object w_shape : string
constrained : boolean
|
|---|---|
| Returns: | w : W object |
Notes
ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.
Examples
>>> import pysal
>>> w1 = pysal.lat2W(4,4,rook=False)
>>> w2 = pysal.lat2W(6,4,rook=True)
>>> w = w_symmetric_difference(w1, w2, constrained=False)
>>> w1[0] == w[0]
False
>>> w1.neighbors[15]
[10, 11, 14]
>>> w2.neighbors[15]
[11, 14, 19]
>>> w.neighbors[15]
[10, 19]
>>>
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 |
|---|---|
| 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
>>> import pysal
>>> w1 = pysal.lat2W(4,4)
>>> w2 = pysal.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]
>>>