I had trouble myself understanding what Joe was driving at, and that
lead to my mistaken call for better sample data.

What Joe is working with is a character matrix - one row of characters
represents one number. So there will be multiple columns in the source
data and that corresponds to a list of integers in the result (one
integer of result for each row of characters).

The empty box was a way of generating the blank row of characters in
the character matrix.

(But the problem is solved, now, so there's not much else to add any more.)

Thanks,

-- 
Raul


On Fri, Apr 13, 2018 at 4:14 PM, Don Guinn <dongu...@gmail.com> wrote:
> Roger said that the boxed sample was only for illustration. But then, where
> does the empty box come from? Or is this a comma or tab delimited file?
> Granted, if the original file is pretty trashy then it is probably
> necessary to do some clean-up ending out in table of boxes. But if the data
> is relatively clean, then maybe skip the boxing step. Something like:
>
> data=:0 : 0
>
> 2 11 xxx 9
>
> 3_ -1 11 3j
>
> )
>
> _&".;._2 data
>
> 2 11 _ 9
>
> _ _1 11 _
>
>
> On Fri, Apr 13, 2018 at 2:04 PM, Joe Bogner <joebog...@gmail.com> wrote:
>
>> Don - the source data is a text file of float data that is being read into
>> J
>>
>> Roger - thanks, for the confirmation. I find that when I'm way from J/APL
>> for awhile, my mind drifts back into "if/then" thinking instead of the
>> simpler and faster method of using multiplication where possible. I fiddled
>> with ^: and @. for over an hour until I posted here, and then in a moment
>> of odd clarity the multiplication idea hit
>>
>> Somewhat tangential -- I recently had to do quantity conversions
>>
>> QuantitySF = IF(UOM="SF",Quantity,UOM="SY",Quantity*9,0)
>>
>> Beautifully (in my opinion) represented as:
>>
>>   qtysf =. qty*(1,9,0) {~ idotfill (>'SF';'SY');uom
>>
>> I'm not nearly as good at keeping references, but this has been highlighted
>> before I think as a hallmark of APL/J elsewhere. I will have to read
>> through the Knuth paper linked
>>
>>
>>
>>
>> On Fri, Apr 13, 2018 at 3:47 PM, Roger Hui <rogerhui.can...@gmail.com>
>> wrote:
>>
>> > Yes, it's a boon that 0 * x is 0 for any x.  Some authors go even
>> further:
>> > Knuth propose to have 0 * x be 0 even when x is an expression which is in
>> > error.  He wanted this to make "Iverson's convention" work in more
>> > situations.  See https://arxiv.org/PS_cache/math/pdf/9205/9205211v1.pdf
>> >
>> >
>> >
>> > On Fri, Apr 13, 2018 at 12:24 PM, Joe Bogner <joebog...@gmail.com>
>> wrote:
>> >
>> > > Well, I stumbled upon a fast way that takes advantage of simple
>> > > multiplication
>> > >
>> > > _ * 0 = 0
>> > > _ * 1 = _
>> > > 5 * 1 = 5
>> > >
>> > >
>> > >    _3 {. (-.@isblank * _&".) c1
>> > > 1.01 _ 0
>> > >    (6!:2) '(isblank * _&".) c1'
>> > > 1.00593
>> > >
>> > > I'm still interested in alternatives that are similar speed if possible
>> > >
>> > >
>> > >
>> > >
>> > >
>> > > On Fri, Apr 13, 2018 at 3:19 PM, Joe Bogner <joebog...@gmail.com>
>> wrote:
>> > >
>> > > > Thank you -- Yes, I didn't want to send along the full sample,
>> > although I
>> > > > could have created some dummy data.
>> > > >
>> > > > Both Don and Raul's method are similar and are equally slow as the
>> way
>> > I
>> > > > had
>> > > >
>> > > > It's not terribly important but I have like 10 numeric columns that I
>> > > > convert in a script and have to painfully wait 30 seconds each time I
>> > run
>> > > > the script. If I could shave 20 seconds off something that I seem to
>> be
>> > > > running multiple times a day and learn something in the process, I
>> > > figured
>> > > > it was worthwhile to ask
>> > > >
>> > > >   (6!:2) '{.@(_&".)"1 c'
>> > > > 3.44371
>> > > >
>> > > > Here's a reasonable approximation:
>> > > >
>> > > > c1 =. 1.5e6 #  (>' ';'bad';'10')
>> > > >
>> > > >
>> > > >  c1=: (((5e6,4)$'1.01'),'bad'),' '
>> > > >    $ c1
>> > > > 5000002 4
>> > > >    (6!:2) '{.@(_&".)"1 c1'
>> > > > 3.29915
>> > > >
>> > > >
>> > > > Compare to
>> > > >
>> > > >  (6!:2) '_ ". c1'
>> > > > 1.01854
>> > > >
>> > > >    _3 {. _ ". c1 NB. bad values at the end... ideally the blank is 0
>> > > though
>> > > > 1.01 _ _
>> > > >
>> > > >
>> > > > On Fri, Apr 13, 2018 at 2:13 PM, Raul Miller <rauldmil...@gmail.com>
>> > > > wrote:
>> > > >
>> > > >> Your sample data does not match your problem description.
>> > > >>
>> > > >> That said,
>> > > >>
>> > > >>    {.@(_&".)"1 > ' ';'bad';'10'
>> > > >> 0 _ 10
>> > > >>
>> > > >> Thanks,
>> > > >>
>> > > >> --
>> > > >> Raul
>> > > >>
>> > > >>
>> > > >> On Fri, Apr 13, 2018 at 2:03 PM, Joe Bogner <joebog...@gmail.com>
>> > > wrote:
>> > > >> > I have a large byte array that I want to convert to a number
>> array.
>> > I
>> > > >> want
>> > > >> > to use _ to indicate a bad value, but blank should be treated as 0
>> > > >> >
>> > > >> >   $ c
>> > > >> > 4862343 10
>> > > >> >
>> > > >> > Instead of this:
>> > > >> >
>> > > >> > asnumber =: _&".
>> > > >> >
>> > > >> >    asnumber  (>' ';'bad';'10')
>> > > >> > _ _ 10
>> > > >> >
>> > > >> > I want this:
>> > > >> >
>> > > >> >
>> > > >> >    asnumber  (>' ';'bad';'10')
>> > > >> > 0 _ 10
>> > > >> >
>> > > >> > This works, but is much slower than I'd like -- nearly 3x slower
>> > than
>> > > >> just
>> > > >> > _ ".
>> > > >> >
>> > > >> >    asnumber =: _ ". '0' ,~^:([: */ ' '&=@])"1  ]
>> > > >> >    asnumber  (>' ';'bad';'10')
>> > > >> > 0 _ 10
>> > > >> >
>> > > >> >    (6!:2) 'asnumber c'
>> > > >> > 3.32579
>> > > >> >    (6!:2) '_&". c'
>> > > >> > 1.35091
>> > > >> >
>> > > >> >
>> > > >> > I have an isblank function that is fast
>> > > >> >
>> > > >> >    isblank =. ([: ({. -:"1 }.) ' '&,)
>> > > >> >    (6!:2) 'isblank c'
>> > > >> > 0.033164
>> > > >> >
>> > > >> > I can't seem to combine the two into something that performs well
>> > > >> without
>> > > >> > doing things at the atom/row level instead of the entire array. I
>> > > >> suspect
>> > > >> > I'm getting tripped up by rank
>> > > >> > ------------------------------------------------------------
>> > > ----------
>> > > >> > For information about J forums see http://www.jsoftware.com/
>> > > forums.htm
>> > > >> ------------------------------------------------------------
>> > ----------
>> > > >> For information about J forums see http://www.jsoftware.com/
>> > forums.htm
>> > > >>
>> > > >
>> > > >
>> > > ----------------------------------------------------------------------
>> > > For information about J forums see http://www.jsoftware.com/forums.htm
>> > >
>> > ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to