pysal.lib.weights.lat2SW

pysal.lib.weights.lat2SW(nrows=3, ncols=5, criterion='rook', row_st=False)[source]

Create a sparse W matrix for a regular lattice.

Parameters:
nrows : int

number of rows

ncols : int

number of columns

rook : {“rook”, “queen”, “bishop”}

type of contiguity. Default is rook.

row_st : boolean

If True, the created sparse W object is row-standardized so every row sums up to one. Defaults to False.

Returns:
w : scipy.sparse.dia_matrix

instance of a scipy sparse matrix

Notes

Observations are row ordered: first k observations are in row 0, next k in row 1, and so on. This method directly creates the W matrix using the strucuture of the contiguity type.

Examples

>>> from pysal.lib.weights import lat2W
>>> w9 = lat2SW(3,3)
>>> w9[0,1]
1
>>> w9[3,6]
1
>>> w9r = lat2SW(3,3, row_st=True)
>>> w9r[3,6] == 1./3
True