regions, neighbors_per_regions = npi.group_by(centers[valid], neighbors[valid])
for region, neighbors_per_region in zip(regions, neighbors_per_regions):
    print(region)
unique_neighbors, neighbor_counts = npi.count(neighbors_per_region)
print((unique_neighbors, neighbor_counts / neighbor_counts.sum() * 100))
Подсчет ячеек соседних областей numpy