Skip to main content
2 of 2
added 39 characters in body
ciao
  • 26k
  • 2
  • 61
  • 142

Ended up with this, which fits my needs of handling numerics not of machine precision. A bit over twice as fast as my OP, so pleased camper:

boxxed[array_] := 
 Module[{w = ArrayPad[array, 1, "Fixed"], 
   masks = {{1 ;; -3, 1 ;; -3}, {3 ;;, 3 ;;}, {3 ;;, 1 ;; -3}, {1 ;; -3, 3 ;;},
            {2 ;; -2, 1 ;; -3}, {2 ;; -2, 3 ;;}, {1 ;; -3, 2 ;; -2}, {3 ;;, 2 ;; -2}}},
  SparseArray[Unitize@Total@Unitize@Map[Subtract[array, w[[Sequence @@ #]]] &, masks], 
    Automatic, 1]["NonzeroPositions"]]

Thanks also to all for the answers!

ciao
  • 26k
  • 2
  • 61
  • 142