Depending on what you are trying to acheive, I think I'd represent the lack
of a match in a row as an empty rather than a _1:

<@I."1 ] 5=m

┌┬─┬─┬─┐

││3│0│2│

└┴─┴─┴─┘


Of course if you need the _1 then you can transform the above

;@([: (a:=])`((<_1),:~ ])} <@I."1) 5 = m


On Mon, Jan 14, 2019 at 10:42 AM 'Skip Cave' via Programming <
[email protected]> wrote:

> What I would really like is for I. to return a _1 whenever there is no 1 in
> the match array, since there cannot be a negative index:
>
> I.5=1 2 3 4 6 4 3 4 4 6 7 6
>
> 4 8 10
>
> Idot 5=1 2 3 4 6 4 3 4 4 6 7 6
>
> _1
>
>
> ]m=.|:1 2 3 4,. 2 3 4 5,. 5 4 3 2 ,. 2 3 5 4
>
> 1 2 3 4
>
> 2 3 4 5
>
> 5 4 3 2
>
> 2 3 5 4
>
> 5=m
>
> 0 0 0 0
>
> 0 0 0 1
>
> 1 0 0 0
>
> 0 0 1 0
>
> ,Idot .5=m
>
> _1 3 0 2
>
>
> Can a verb Idot be designed, that does this?
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Sun, Jan 13, 2019 at 2:41 PM Henry Rich <[email protected]> wrote:
>
> > Right.  Prefer (I.@:= ,) to I.@,@:= since it uses special code.
> >
> > Henry Rich
> >
> > On 1/13/2019 2:54 PM, 'Mike Day' via Programming wrote:
> > > You often see this sort of thing, returning pairs of indices of all
> > occurrences:
> > >
> > >     5 ($@] #.inv I.@,@:=) |: 1 2 3 4,. 2 3 4 5,. 5 4 3 2 ,. 2 3 5 4
> > > 1 3
> > > 2 0
> > > 3 2
> > >
> > > You can obviously get the row indices using {:”1 or some such, and you
> > can of course make the bracketed code a named dyadic verb,
> > >
> > > Cheers,
> > >
> > > Mike
> > >
> > >
> > > Sent from my iPad
> > >
> > >> On 13 Jan 2019, at 17:55, 'Skip Cave' via Programming <
> > [email protected]> wrote:
> > >>
> > >> I know I can find the location (index) of a specific integer in a
> > vector of
> > >> integers using I.
> > >>
> > >> I.5=1 2 3 4 5 4 3 4 5 6 5 6
> > >>
> > >> 4 8 10
> > >>
> > >>
> > >> So I want to find the row index of a specific integer in an array of
> > >> integers:
> > >>
> > >> |:1 2 3 4,. 2 3 4 5,. 5 4 3 2 ,. 2 3 5 4
> > >>
> > >> 1 2 3 4
> > >>
> > >> 2 3 4 5
> > >>
> > >> 5 4 3 2
> > >>
> > >> 2 3 5 4
> > >>
> > >> 5=|:1 2 3 4,. 2 3 4 5,. 5 4 3 2 ,. 2 3 5 4
> > >>
> > >> 0 0 0 0
> > >>
> > >> 0 0 0 1
> > >>
> > >> 1 0 0 0
> > >>
> > >> 0 0 1 0
> > >>
> > >> ,I. 5=|:1 2 3 4,. 2 3 4 5,. 5 4 3 2 ,. 2 3 5 4
> > >>
> > >> 0 3 0 2
> > >>
> > >>
> > >> The first zero indicates that there is no 5 in the first row. The
> second
> > >> zero gives the index of the 5 in the third row. How can I tell whether
> > the
> > >> zero is an index, or a null indicator?
> > >>
> > >> Skip
> > >> ----------------------------------------------------------------------
> > >> For information about J forums see
> http://www.jsoftware.com/forums.htm
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> >
> > ---
> > This email has been checked for viruses by AVG.
> > https://www.avg.com
> >
> > ----------------------------------------------------------------------
> > 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