Another option separates structure from data. Given an initial matrix M, build:
DATA=: (,M),0 T=. 1 1}._1 _1}. i.2+$M NDX=: ($M) $"1 T i.&,"2 T +"2 0 ] 0, (2+$y) #. _1 ^ #: i. 4 Now, NDX { DATA will give you a 5 item list of matrices which represent the five desired sample points. Note that NDX only has to be computed once (unless you are changing the size of the data you are working with). If you want to change the padding value used for the "off the edge" case, you can change the last item in DATA. -- Raul On Tue, Nov 13, 2012 at 3:48 PM, <neit...@gaertner.de> wrote: >>OK, I'm trying to do some work with matrices that involves transformations >>based on local properties of a matrix (neighbouring elements). > > As Henry Rich pointed out: the real solution will go via ;.3 tessalations. > Have a look at those. > > Without those ;.3 cuts, the classic approach is this: > > A little to the left > Right down the middle > A little to the right, > X marks the spot > [Godley & Creme, This Sporting Life, 1978] > > Solve the torus first: > > use |. to wiggle m up & down (and center), > use |."1 to wiggle those matrices left & right (and center) > > ending up with 9 matrices, the original one and eight shifted ones, where > the neighbours get shifted to "the original" position. +/+/, and subtract > the original matrix agin if you want to sum up neighbours only, and you are > done. > > You'll need to use "l r a lot to make this work, left as an healthy > exercise for you. > > For the non-torus problem: > > Pad m with borders of zeroes (easy with , and ,.), > do the torus sums, > throw away the borders of the sums. > > Martin > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm