Suppose I have a lattice of points in d times Z with equal spacing apart, how can I efficiently convert this into a graph with nodes being the points and an edge between two points if and only if those points are adjacent?
For example: suppose we're given points in the integers squared corresponding to the vertices of a square... How can we convert this into a 4 by 4 matrix (or graph) with entries 1 or 0 is there are edges connecting the two nodes (which correspond to the points in the integers squared)
The example is simple for two reasons:
- The points lie in R squared, so the input is a 2-dimensional array (where in general the input would be a d-dimensional array; d>1
- Most points are connected in an obvious way... but the pattern (at least I find) becomes less apparent in d-dimensions, with more points on each axis.... (which is even clear if we take the 8 points lying on the edge of a cube).
I'm looking for a code which can implement this given any such array (As an input) and outputs a (necessarily symmetric) matrix representing the edges between the nodes on the graph.
I programming in R (and am open to learning Python).
Ps.s:I apologize for the odd syntax... this exchange is not compatible with LaTeX apparently... :0