Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def Queen_higher(dataframe, k):
first_order = libpysal.weights.Queen.from_dataframe(dataframe)
joined = first_order
for i in list(range(2, k + 1)):
i_order = libpysal.weights.higher_order(first_order, k=i)
joined = libpysal.weights.w_union(joined, i_order)
return joined
import libpysal
import geopandas as gpd
tessellation = gpd.read_file("/Users/martin/Dropbox/StrathUni/PhD/Sample Data/Prague/Tests/181122/tess_oldtown_nid.shp")
weights_queen = libpysal.weights.Queen.from_dataframe(tessellation) # classic queen of 1st order
second_order = libpysal.weights.higher_order(weights_queen, k=2) # second order neighbours (only)
joined_weights = libpysal.weights.w_union(weights_queen, second_order) # joined together
weights_queen.neighbors[10]
second_order.neighbors[10]
joined_weights.neighbors[10]
def Queen_higher(dataframe, k):
first_order = libpysal.weights.Queen.from_dataframe(dataframe)
joined = first_order
for i in list(range(2, k + 1)):
i_order = libpysal.weights.higher_order(first_order, k=i)
joined = libpysal.weights.w_union(joined, i_order)
return joined
fourth = Queen_higher(tessellation, k=4)
fourth.mean_neighbors