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