libpysal.weights.lat2SW¶
- libpysal.weights.lat2SW(nrows=3, ncols=5, criterion='rook', row_st=False)[source]¶
Create a sparse W matrix for a regular lattice.
- Parameters:
- Returns:
- w
scipy.sparse.dia_matrix
instance of a scipy sparse matrix
- w
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 libpysal.weights import lat2SW >>> w9 = lat2SW(3,3) >>> w9[0,1] == 1 True >>> w9[3,6] == 1 True >>> w9r = lat2SW(3,3, row_st=True) >>> w9r[3,6] == 1./3 True