A variant on what Rob suggested:
    'ab' +./ . E."1 arr
1 0 0 1 0 0 1 0 0 1



On Thu, Aug 28, 2014 at 9:35 AM, 'Pascal Jasmin' via Programming <
programm...@jsoftware.com> wrote:

> Raul's code is there to mostly handle strings of variable size. It can be
> generalized though:
>
>    'abc' (] -:"1  ,:@:{:@:$@:] {. [) 'abd','abc' ,: 'yyy'
> 0 1 0
>
>    'abc' (] *./"1@e.  ,:@:{:@:$@:] {. [) 'abd','abc' ,: 'yyy'
> 0 1 0
>
> if your search array has no padding/fills or you know the fixed length,
> then just -:"1 is what I think you want, though variations with e. work if
> you are interested in partial matches.
>
>
> ----- Original Message -----
> From: Joe Bogner <joebog...@gmail.com>
> To: programm...@jsoftware.com
> Cc:
> Sent: Thursday, August 28, 2014 8:12:46 AM
> Subject: Re: [Jprogramming] locating indices of string in list of strings
>
> Tracy - symbols are a good way to go. Thanks for reminding me of them.
>
> Raul - that's what I was missing... I needed to use e. with the same
> shape: eg.  arr e. (1 3 $ 'ab ')... Thank you.  Your examples are nice
> and generic and faster than -:"1
>
> ( I have a 68 million row memory mapped table of 8 character strings I
> am searching )
>
> arr =: 1e8 2 $ ('ab','cd')
>    timespacex '''ab'' -:"1 arr'
> 0.543927 1.34219e8
>    timespacex 'arr e. ,:({:$arr){.''ab'''
> 0.398904 1.3435e8
>
> ('ab' -:"1 arr) -: (arr e. ,:({:$arr){.'ab')
>
> Of course on my actual data it's slightly different:
>
> timespacex '''ZZZZ145'' -:"1 p'
> 0.109682 1.3422e8
>    timespacex '(p e. ,:({:$p){.''ZZZZ145'')'
> 0.728868 1.34222e8
>
> $ p
> 68242450 8
>
> ((p e. ,:({:$dat__p){.'ZZZZ145')) -: ('ZZZZ145' -:"1 p)
> 1
>
> bill - Not sure what to do with E.
>
> Bjorn - 'ab' I. arr doesn't seem to help either... I was hoping for a
> mask of 0 1 0 1 for whether it was found or the indices
>
> On Thu, Aug 28, 2014 at 7:56 AM, Björn Helgason <gos...@gmail.com> wrote:
> > 'ab' I. arr
> >
> > __-------------------_
> > https://groups.google.com/forum/m/#!forum/havaogskulamal
> > On 28 Aug 2014 10:58, "Joe Bogner" <joebog...@gmail.com> wrote:
> >
> >> Apologies for the extremely basic question, but I am struggling with
> >> this after searching NuVoc and the dictionary.
> >>
> >> How do I locate all the indices of 'ab' in arr?
> >>
> >> arr=:10 $ > ;: 'ab cd yyy'
> >>
> >> surely this isn't the best way:
> >>
> >> ] (3 = +/"1 'ab' i. arr) # arr
> >> ab
> >> ab
> >> ab
> >> ab
> >>
> >>
> >> I have been primarily dealing with boxed strings up to this point,
> >> which seemed easier since it was locating an atom in a list, not a
> >> list in a table (practicing my vocabulary here... I might be wrong
> >> though)
> >>
> >>
> >> Thanks,
> >> Joe
> >> ----------------------------------------------------------------------
> >> 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
>



-- 
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to