Skip to content
Advertisement

How to make a networkX grid given a list of points and add edge weights?

I have a list of points (x, y) whose values are from 0 to 1

JavaScript

I’m trying to generate a 2D grid of these points using NetworkX, and also add edge weights to the graph where the weight from one node to its neighbor is simply the Euclidean distance.

I am not sure about how to go about this though: I’m not very sure how to split my list of points into the m and n required for nx.generators.lattice.grid_2d_graph, nor how to update the edge weights for each one. When I try something like

JavaScript

a different graph is generated each time, even the nodes are the same.

Advertisement

Answer

IIUC you want something like this?

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement