def neighborhood(centerIndex, radius, dimensions):
 centerPosition = coordinatesFromIndex(centerIndex, dimensions)
 intervals = []
 for (i, dimension) in enumerate(dimensions):
  left = max(0, (centerPosition[i] - radius))
  right = min((dimension - 1), (centerPosition[i] + radius))
  intervals.append(xrange(left, (right + 1)))
 coords = numpy.array(list(itertools.product(*intervals)))
 return numpy.ravel_multi_index(coords.T, dimensions)

def neighborhood ( centerIndex , radius , dimensions ) : centerPosition = coordinatesFromIndex ( centerIndex , dimensions ) intervals = [ ] for ( i , dimension ) in enumerate ( dimensions ) : left = max ( 0 , ( centerPosition [ i ] - radius ) ) right = min ( ( dimension - 1 ) , ( centerPosition [ i ] + radius ) ) intervals . append ( xrange ( left , ( right + 1 ) ) ) coords = numpy . array ( list ( itertools . product ( * intervals ) ) ) return numpy . ravel_multi_index ( coords . T , dimensions )
get the points in the neighborhood of a point .