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