pysal.lib.weights.w_subset

pysal.lib.weights.w_subset(w1, ids, silence_warnings=False)[source]

Returns a binary weights object, w, that includes only those observations in ids.

Parameters:
w1 : W

object

ids : list

A list containing the IDs to be include in the returned weights object.

silence_warnings : boolean

Switch to turn off (default on) print statements for every observation with islands

Returns:
w : W

object

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 pysal.lib.weights import lat2W
>>> import pysal.lib
>>> w1 = lat2W(6,4)
>>> ids = range(16)
>>> w = pysal.lib.weights.set_operations.w_subset(w1, ids)
>>> w1[0] == w[0]
True
>>> w1.neighbors[15]
[11, 14, 19]
>>> w.neighbors[15]
[11, 14]
>>>