Haven't looked at the other solutions (in detail) and come up with
slice=: 3 :0
Y=. |: y
z=. </./ Y
t=. (e.~ i.@>:@(>./)) {. Y
t #^:_1 z
)
slice data
+-----+---+-++-+
|1 2 3|1 3|1||1|
+-----+---+-++-+
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens John Randall
> Verzonden: donderdag 5 mei 2011 17:07
> Aan: [email protected]
> Onderwerp: [Jprogramming] Keys problem
>
> I have a set of ordered pairs of nonnegative integers (representing pixels
> that are set in a binary image). To speed up access, I want to produce an
> array s of boxes such that (x,y) is an ordered pair if and only if y e. x
{:: s .
> Keys would work perfectly for this except for skipped x-values, so I work
> around it, essentially inserting a bogus y-value for every x-value, and
then
> removing it.
>
> data=:>0 1;0 2;0 3;1 1;1 3;2 1;4 1
>
> slice=:3 : 0
> 'X Y'=.|:/:~ y
> m=.>:>./X
> n=.>:>./Y
> X=.(i.m),X
> Y=.(m#n),Y
> -.&n &.> X</.Y
> )
> slice data
> +-----+---+-++-+
> |1 2 3|1 3|1||1|
> +-----+---+-++-+
>
> I also have a test verb.
>
> test=:3 : 0
> y=./:~y
> s=.slice y
> y-:;(<"0 i.#s)(,"_ 0)&.> s
> )
>
> test data
> 1
>
> Does anyone have any suggestions as to how to do this better?
>
> Best wishes,
>
> John
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm