pysal.lib.weights.WSP2W

pysal.lib.weights.WSP2W(wsp, silence_warnings=False)[source]

Convert a pysal WSP object (thin weights matrix) to a pysal W object.

Parameters:
wsp : WSP

PySAL sparse weights object

silence_warnings : boolean

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

Returns:
w : W

PySAL weights object

Examples

>>> from pysal.lib.weights import lat2W, WSP

Build a 10x10 scipy.sparse matrix for a rectangular 2x5 region of cells (rook contiguity), then construct a PySAL sparse weights object (wsp).

>>> sp = lat2SW(2, 5)
>>> wsp = WSP(sp)
>>> wsp.n
10
>>> wsp.sparse[0].todense()
matrix([[0, 1, 0, 0, 0, 1, 0, 0, 0, 0]], dtype=int8)

Convert this sparse weights object to a standard PySAL weights object.

>>> w = WSP2W(wsp)
>>> w.n
10
>>> print(w.full()[0][0])
[0. 1. 0. 0. 0. 1. 0. 0. 0. 0.]