libpysal.weights.
higher_order
(w, k=2, **kwargs)[source]¶Contiguity weights object of order k.
spatial weights object
order of contiguity
optional arguments for pysal.weights.W
spatial weights object
Notes
Proper higher order neighbors are returned such that i and j are k-order neighbors iff the shortest path from i-j is of length k.
Examples
>>> from libpysal.weights import lat2W, higher_order
>>> w10 = lat2W(10, 10)
>>> w10_2 = higher_order(w10, 2)
>>> w10_2[0] == {2: 1.0, 11: 1.0, 20: 1.0}
True
>>> w5 = lat2W()
>>> w5[0] == {1: 1.0, 5: 1.0}
True
>>> w5[1] == {0: 1.0, 2: 1.0, 6: 1.0}
True
>>> w5_2 = higher_order(w5,2)
>>> w5_2[0] == {10: 1.0, 2: 1.0, 6: 1.0}
True