libpysal.weights.lat2W¶
- libpysal.weights.lat2W(nrows=5, ncols=5, rook=True, id_type='int', **kwargs)[source]¶
Create a W object for a regular lattice.
- Parameters:
- nrows
int
number of rows
- ncols
int
number of columns
- rookbool
type of contiguity. Default is rook. For queen, rook =False
- id_type
str
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’, …)
- **kwargs
keyword
arguments
optional arguments for
pysal.weights.W
- nrows
- Returns:
- w
W
instance of spatial weights class W
- w
Notes
Observations are row ordered: first k observations are in row 0, next k in row 1, and so on.
Examples
>>> from libpysal.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