1

I have the next array:

DeleteCases[DiskMatrix[radius], 0, {2}]

And I would like to have access to each element first neighbors. How can I have access to those elements?

Ask8
  • 637
  • 3
  • 6

1 Answers1

2
dm = DiskMatrix[3];
nzp = Position[dm, 1];

RelationGraph[ChessboardDistance[##] == 1 &, nzp, 
 VertexCoordinates -> nzp,  
 PlotTheme -> "VintageDiagram", 
 VertexSize -> {.35, .2}, 
 ImageSize -> 1 -> 50]

enter image description here

Use ManhattanDistance[##] == 1 & in the first argument to get

enter image description here

Note: You can also define nzp as:

nzp = SparseArray[dm]["NonzeroPositions"]; 
kglr
  • 394,356
  • 18
  • 477
  • 896