libpysal.weights.w_subset¶
- libpysal.weights.w_subset(w1, ids, **kwargs)[source]¶
Returns a binary weights object, w, that includes only those observations in ids.
- Parameters:
- Returns:
- w
W
object
- w
Examples
Construct a rook weights matrix for a 6x4 region (24 areas). By default PySAL assigns integer IDs to the areas in a region. By passing in a list of integers from 0 to 15, the first 16 areas are extracted from the previous weights matrix, and only those joins relevant to the new region are retained.
>>> from libpysal.weights import lat2W, w_subset >>> w1 = 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]