Or: f 3 3 +/@:((0) 4} ,);._3 ([: |: {: , ] , {.)^:2 f 1+i.3 3 44 43 42 41 40 39 38 37 36
Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Aai Sent: Tuesday, November 13, 2012 8:17 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Matrix Transformations based on local submatrices Hmmm, no need for selecting, so: 3 3 +/@:((0) 4},);._3 |:@({:,],{.)^:(2)1+i.3 3 On 13-11-12 14:13, Aai wrote: > Just a possibility for the interesting case of a torus: > > 3 3 +/@:(#~0<])@((0) 4},);._3 |:@({:,],{.)^:(2)1+i.3 3 > 44 43 42 > 41 40 39 > 38 37 36 > > > torus elements flattened: > > |:@({:,],{.)^:(2)1+i.3 3 > > and then using > 3 3 f ;. _3 > > with f selecting and summing > > > > On 13-11-12 12:43, Alex Giannakopoulos wrote: >> OK, I'm trying to do some work with matrices that involves >> transformations based on local properties of a matrix (neighbouring >> elements). >> This is the sort of thing you may find in image-processing >> "edge-detection", etc, or in some cellular automata of the type of >> Conway's "Life". >> >> In other words, I want to be able to supply a matrix, and have it so >> processed that the result is a new matrix where each new element was >> determined by a function which processed the old elements neighbours. >> >> Any direction, relevant help pages, etc, much appreciated. >> If anyone would go as far as offering some sample code that would be >> great, too! >> As a trivial example, suppose I want to calculate the sum of the >> neighbours of each element Say we have a matrix m0 =. 3 3 $ >:i.9 >> What I want is the verb "neighbours" whereby >> neighbours m0 >> 11 19 13 >> 23 40 27 >> 17 31 19 >> >> Obviously, I am maily interested in how to extract the "neighbours" >> submatrix, without resorting to explicit looping, if that is possible. >> To make it a bit more interesting, how would I extract the neighbours >> if the matrix was a torus or infinite tiling, such that: >> neighb-torus m0 >> 44 43 42 >> 41 40 39 >> 38 37 36 >> >> Thanks for any suggestions! >> Alex >> --------------------------------------------------------------------- >> - For information about J forums see >> http://www.jsoftware.com/forums.htm > -- Met vriendelijke groet, @@i = Arie Groeneveld ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm