# libpysal.weights.higher_order_sp

libpysal.weights.higher_order_sp(w, k=2, shortest_path=True, diagonal=False, lower_order=False, **kwargs)

  Contiguity weights for either a sparse W or W for order k.

  Parameters:
    w `W`

      sparse_matrix, spatial weights object or scipy.sparse.csr.csr_instance

    k `python:int`

      Order of contiguity

    shortest_path bool

      True: i,j and k-order neighbors if the shortest path for i,j is k. False: i,j are k-order neighbors if there is a path from i,j of length k.

    diagonal bool

      True: keep k-order (i,j) joins when i==j False: remove k-order (i,j) joins when i==j

    lower_order bool

      True: include lower order contiguities False: return only weights of order k

    **kwargs `keyword` `arguments`

      optional arguments for `pysal.weights.W`

  Returns:
    wk `W`

      WSP, type matches type of w argument

  Examples

      >>> from libpysal.weights import lat2W, higher_order_sp
      >>> w25 = lat2W(5,5)
      >>> w25.n
      25
      >>> w25[0] == {1: 1.0, 5: 1.0}
      True
      >>> w25_2 = higher_order_sp(w25, 2)
      >>> w25_2[0] == {10: 1.0, 2: 1.0, 6: 1.0}
      True
      >>> w25_2 = higher_order_sp(w25, 2, diagonal=True)
      >>> w25_2[0] ==  {0: 1.0, 10: 1.0, 2: 1.0, 6: 1.0}
      True
      >>> w25_3 = higher_order_sp(w25, 3)
      >>> w25_3[0] == {15: 1.0, 3: 1.0, 11: 1.0, 7: 1.0}
      True
      >>> w25_3 = higher_order_sp(w25, 3, shortest_path=False)
      >>> w25_3[0] == {1: 1.0, 3: 1.0, 5: 1.0, 7: 1.0, 11: 1.0, 15: 1.0}
      True
      >>> w25_3 = higher_order_sp(w25, 3, lower_order=True)
      >>> w25_3[0] == {
      ...     5: 1.0, 7: 1.0, 11: 1.0, 2: 1.0, 15: 1.0, 6: 1.0, 10: 1.0, 1: 1.0, 3: 1.0
      ... }
      True