# pysal.lib.weights.higher_order_sp¶

pysal.lib.weights.higher_order_sp(w, k=2, shortest_path=True, diagonal=False)[source]

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 : int Order of contiguity shortest_path : boolean 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 : boolean True: keep k-order (i,j) joins when i==j False: remove k-order (i,j) joins when i==j wk : W WSP, type matches type of w argument

Notes

Lower order contiguities are removed.

Examples

>>> from pysal.lib.weights import lat2W
>>> import pysal.lib
>>> w25 = lat2W(5,5)
>>> w25.n
25
>>> w25[0] == {1: 1.0, 5: 1.0}
True
>>> w25_2 = pysal.lib.weights.util.higher_order_sp(w25, 2)
>>> w25_2[0] == {10: 1.0, 2: 1.0, 6: 1.0}
True
>>> w25_2 = pysal.lib.weights.util.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 = pysal.lib.weights.util.higher_order_sp(w25, 3)
>>> w25_3[0] == {15: 1.0, 3: 1.0, 11: 1.0, 7: 1.0}
True
>>> w25_3 = pysal.lib.weights.util.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