A way to do the work:

Characters -> Numbers
Based on your data:
    aa
┌──┬──┬─┬──┬───┬───┬───┐
│6 │30│1│17│119│118│116│
├──┼──┼─┼──┼───┼───┼───┤
│63│2 │5│17│103│14 │1  │
└──┴──┴─┴──┴───┴───┴───┘

NB. translate transposed array in string of characters
        ":  |:  >  aa
  6  63
 30   2
  1   5
 17  17
119 103
118  14
116   1

Let's do it step by step
   NB. example a & b are strings of characters
   a =: '  6  .  '
   b =: ' 6   62 '

   NB. append (characters)
   ] c =: a , b
  6  .   6   62

   NB. find non blank characters from c
   ' ' ~: c
0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0

   NB. extract all non blank characters
   (' ' ~: c)   # c
 6.662

   NB. translate -> numbers
   ". (' ' ~: c) # c
6.662

    NB. test the number
   1 + ( ". (' ' ~: c) # c)
7.662

    NB. make a tacit verb for the all process
    tr1 =: ' '& ~:

    tr1 c
0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0

    NB. extraction of non blank
    tr2 =: 13 : ' (tr1 y) # y'

    tr2 c
6.662

    NB. final verb
    tr3 =: 13 : ' do tr2 y'

   tr3 c
6.662

   tr3 =: tr3 f.  NB. fix the definition

   tr3            NB. display the definition
[: ". ' '&~: # ]

   NB. test on a pair of data
   tr3 a , b
6.662

   NB. work on all your data
   tr3"1  ": |: > aa   NB. your data are aa , unboxed, transposed & translate
                       NB. in characters
663 302 15 1717 119103 11814 1161

    NB. or
   ,. tr3"1  (": |: > aa)
   663
   302
    15
  1717
119103
 11814
  1161


5, 2011 at 7:29 AM, bill lam <[email protected]> wrote:
>
> It could also use & instead of &: since rank of monad ": is infinity.
>
> Птн, 15 Июл 2011, bill lam писал(а):
> > First observe for 2 numbers,
> >    6 ,&": 63
> > 663
> >
> > generalise it with rank operator to work on pairs of scalar number
> >    (>{.aa) ,&:":"0 (>{:aa)
> > 663
> > 302
> > 15
> > 1717
> > 119103
> > 11814
> > 1161
> >
> > This is a character vector, to turn it back into number, it needs
> >    (>{.aa) ".@,&:":"0 (>{:aa)
> > or
> >    (>{.aa) ".@:,&:":"0 (>{:aa)
> > 663 302 15 1717 119103 11814 1161
> >
> >
> > Чтв, 14 Июл 2011, PackRat писал(а):
> > > I wish to append the digits of two numbers to form a new number:
> > >   12  345  -->  12345
> > >
> > > I'm sure this is elementary, but I'm currently stumped.  Here's some
> > > data (which in reality would have been read in from a CSV file and then
> > > transposed):
> > >
> > > aa=. 2 7 $ 6;30;1;17;119;118;116;63;2;5;17;103;14;1
> > >
> > > +--+--+-+--+---+---+---+
> > > |6 |30|1|17|119|118|116|
> > > +--+--+-+--+---+---+---+
> > > |63|2 |5|17|103|14 |1  |
> > > +--+--+-+--+---+---+---+
> > >
> > > Then I pulled out the numeric data pairs, converted them to literals,
> > > and appended them:
> > >
> > > b=. ( ": every 0{aa ) ,. ( ": every 1{aa )
> > >
> > > 6  63
> > > 30 2
> > > 1  5
> > > 17 17
> > > 119103
> > > 11814
> > > 1161
> > >
> > > Just for visual purposes here (NOT in J!), I substituted * for spaces,
> > > to show what's happening:
> > >
> > > 6**63*
> > > 30*2**
> > > 1**5**
> > > 17*17*
> > > 119103
> > > 11814*
> > > 1161**
> > >
> > > However, what I want to end up with is this, no spaces, different
> > > lengths:
> > >
> > > 663
> > > 302
> > > 15
> > > 1717
> > > 119103
> > > 11814
> > > 1161
> > >
> > > To attempt to do this, I did the following:
> > >
> > > spc=. ' ' E. every b
> > >
> > > 0 1 1 0 0 1
> > > 0 0 1 0 1 1
> > > 0 1 1 0 1 1
> > > 0 0 1 0 0 1
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 1
> > > 0 0 0 0 1 1
> > >
> > > keepmask=. (0 = spc)
> > >
> > > 1 0 0 1 1 0
> > > 1 1 0 1 0 0
> > > 1 0 0 1 0 0
> > > 1 1 0 1 1 0
> > > 1 1 1 1 1 1
> > > 1 1 1 1 1 0
> > > 1 1 1 1 0 0
> > >
> > > I thought that the following would accomplish what I wanted, but it
> > > does NOT:
> > >
> > > nospc=. keepmask # each b
> > >
> > > +-+-+-+-+-+-+
> > > |6| | |6|3| |
> > > +-+-+-+-+-+-+
> > > |3|0| |2| | |
> > > +-+-+-+-+-+-+
> > > |1| | |5| | |
> > > +-+-+-+-+-+-+
> > > |1|7| |1|7| |
> > > +-+-+-+-+-+-+
> > > |1|1|9|1|0|3|
> > > +-+-+-+-+-+-+
> > > |1|1|8|1|4| |
> > > +-+-+-+-+-+-+
> > > |1|1|6|1| | |
> > > +-+-+-+-+-+-+
> > >
> > > Essentially, this puts me right back where I started, without
> > > accomplishing anything.  I thought it would be a very straightforward
> > > process to append the digits of two numbers--it's sort of the reverse
> > > of what was discussed here recently.  The final step, of course, is to
> > > convert the new literal back into a number (but that part's easy!).
> > >
> > > I appreciate any help with this--thanks in advance!
> > >
> > > Harvey
> > >
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > --
> > regards,
> > ====================================================
> > GPG key 1024D/4434BAB3 2008-08-24
> > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


--
Daniel Durieu
Rue du Grand Coron, 28
B-7034-Obourg
Tél: 065/ 72 32 14

e-mail: [email protected]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to