# libpysal.weights.lat2SW

libpysal.weights.lat2SW(nrows=3, ncols=5, criterion='rook', row_st=False)

  Create a sparse W matrix for a regular lattice.

  Parameters:
    nrows `python:int`

      number of rows

    ncols `python:int`

      number of columns

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

      type of contiguity. Default is rook.

    row_st bool

      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 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