1
$\begingroup$

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?

$\endgroup$
1

1 Answer 1

2
$\begingroup$
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"]; 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.