They do _under_ conversion to numbers and under open.


On Fri, Apr 13, 2018 at 2:49 PM, Raul Miller <rauldmil...@gmail.com> wrote:

> I remember at one point wishing that these would all work on character
> and boxed data.
>
> Thanks,
>
> --
> Raul
>
>
> On Fri, Apr 13, 2018 at 4:25 PM, Roger Hui <rogerhui.can...@gmail.com>
> wrote:
> > It's useful to have at your fingertips a (small) set of manoeuvers:
> >
> > x * 0 = 0
> > x * 1 = x
> >
> > x ^ 0 = 1
> > x ^ 1 = x
> >
> > etc.
> >
> > The  Y {~ X i. x  phrase, for mapping cells in X to values in Y, is also
> > generally useful.  See the Dyalog APL blog post Calcultion v Look-Up
> > <https://www.dyalog.com/blog/2017/04/calculation-v-look-up/>.  (It's APL
> > rather than J but you can handle that, right? :-)  I read somewhere that
> > Google uses that (looking up instead of calculating) a lot, but I don't
> > have the reference now.
> >
> >
> >
> > On Fri, Apr 13, 2018 at 1: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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to