I am trying to apply my understanding of image binning in Julia (which at its heart is an operation that needs to be performed on a 2D array) . To that end I created a toy array

I guess, where I am stuck is coding a loop that will raster the kernel along a height and width of an input array and return a new array that is a fraction of the input size which in this case would be a 5x5 array.

Yes, i think the specific question is, how do you raster along the dimensions of an array such that the resultatnt array is a fraction of its size. eg. a 10x10 array is now a 5x5 array because each element in the smaller array is an average of a 2x2 kernel.

To continue where you were originally doing, you want to make a b that is 5x5 and then, for each b[i,j] you want to look at the corresponding 2x2 in a, so, if i=1, j=1, you want to look at a[1:2, 1:2]; i=2, j=3 <= a[3:4, 5:6] etc…

which will probably get you pretty far. As an added tip, arithmetic woks on CartesianIndex as though it were a scalar, as do functions like one, zero, etc, which you may find yourself needing.