Have you considered j numbers?

   data=:0j1 0j2 0j3 1j1 1j3 2j1 4j1
   9  o. data
0 0 0 1 1 2 4
   11  o. data
1 2 3 1 3 1 1


2011/5/5 John Randall <[email protected]>

> 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
>



-- 
Björn Helgason, Verkfræðingur
Fornustekkum II
781 Hornafirði,
t-póst: [email protected]
gsm: +3546985532
twitter: @flugfiskur
http://groups.google.com/group/J-Programming


Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans

góður kennari getur stigið á tær án þess að glansinn fari af skónum
          /|_      .-----------------------------------.
         ,'  .\  /  | Með léttri lund verður        |
     ,--'    _,'   | Dagurinn í dag                     |
    /       /       | Enn betri en gærdagurinn  |
   (   -.  |        `-----------------------------------'
   |     ) |         (\_ _/)
  (`-.  '--.)       (='.'=)   ♖♘♗♕♔♙
   `. )----'        (")_(") ☃☠
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to