pysal.lib.weights.lat2W

pysal.lib.weights.lat2W(nrows=5, ncols=5, rook=True, id_type='int')[source]

Create a W object for a regular lattice.

Parameters:
nrows : int

number of rows

ncols : int

number of columns

rook : boolean

type of contiguity. Default is rook. For queen, rook =False

id_type : string

string defining the type of IDs to use in the final W object; options are ‘int’ (0, 1, 2 …; default), ‘float’ (0.0, 1.0, 2.0, …) and ‘string’ (‘id0’, ‘id1’, ‘id2’, …)

Returns:
w : W

instance of spatial weights class W

Notes

Observations are row ordered: first k observations are in row 0, next k in row 1, and so on.

Examples

>>> from pysal.lib.weights import lat2W
>>> w9 = lat2W(3,3)
>>> "%.3f"%w9.pct_nonzero
'29.630'
>>> w9[0] == {1: 1.0, 3: 1.0}
True
>>> w9[3] == {0: 1.0, 4: 1.0, 6: 1.0}
True