I have a NxN matrix.
For each 2x2 subarray of this (keep it simple, N is even), I want to calculate 
the maximum value and if the value of that cell equals the maximum of the 2x2 
subarray write 1, else write 0.

e.g. 
NB. T arbitrary 10x10 matrix
T =: 10 10 $ 0 _2 12 100 2 4.5 1 7 _5.5 3.2 120 2 _100 3 5 18 4

interval =: ;.1
is =:  10 $ 1 0

 IsMax =: (is;is)   ($$((>./=])@:,))&.>@:< interval T

So IsMax shows which elements are the max values of the 4x4 subarrays.

Now I want to unbox and keep the indices correct.

This appears to work

10 10 $ , > |:"2  <"1 > IsMax

But is incredibly messy. I'm hoping there is a nicer/ more terse / elegant way 
to do this.

Thanks,
Jon
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to