Thanks a lot to all for enlightening me! > DATA=: ".;._2]0 :0 0 0 1 1 1 1 2 2 2 2 2 4 4 4 5 5 5 0 7 8 9 2 2 5 5 5 3 8 > 0 0 5 6) > > 6 (</./@] #inv~ i.@[ e. {.@] ) DATA > 6 {. (</./ #inv~ (e.~ i.@(1 + >./))@{. ) DATA > I could not choose between these options without better understanding > your application.
Well, my application ... continue reading at your own risk. I have (say) a million points (x,y,z) and I use software that makes a Delaunay triangulation (http://www.cs.cmu.edu/~quake/triangle.html): approximately two million triangles. Each triangle consists of three point numbers. Although my points are 3D, the triangulation is 2D and z is merely an attribute (it is terrain height, but it could also be temperature). With each point I want to do "something" , which also depends on the point's neighbours: those points that are together with the considered point in a triangle. This is going to happen very often (different things that I want to do), and therefore I wondered whether it makes sense to find each point's set of neighbours only once and store that. Since the number of neighbours is not the same for each point (on average it is six), I was thinking of a boxed list. Occasionally an (x,y) occurs twice in the input data. Then only one of these points is used in the triangulation and for the other I get an empty slot in my list. Suppose $tri = 3 1000000. I start off by making a 3x3000000 matrix tri,.(1|.tri),.2|.tri I sort it from left to right according to the top row and then something like </. comes in. After that it gets again a bit complicated since I want the neighbours to be ordered (counter-clockwise). Fortunately all input triangles have the same orientation. One of the things I want to do is check how well a point and its neighbours fit in a 3D plane. If they fit very well, I might remove the point and re-triangulate locally, and do this smart & recursively. Depending on the scene, most of the data might get removed without losing much information. I wonder how this will look in J :-) Another envisaged use for storing the neighbours with each point is answering the question: which triangle contains a given (x,y). Normally this requires visiting half of the triangles on average (one million), or using a spatial index. Now it will be possible to start at an arbitrary location, step through a sequence of adjacent triangles in the right direction, and arrive after one thousand steps or so. If anybody read till here and thinks this is interesting: suggestions will be highly appreciated! ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm