Apply a function to a margin of an array
