Just focusing on the result I would say:

(<@:({:"1)/.~{."1) data
┌─────┬───┬─┬─┐
│1 2 3│1 3│1│1│
└─────┴───┴─┴─┘


Hallo John Randall, je schreef op 05-05-11 17:06:
> 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

-- 
Met vriendelijke groet,
=@@i

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

Reply via email to