Hi Thomas,
I usually use something like this which relies on Category ({) to group the
indices generated by i. applied to each index of the shape. I imagine others
have different approaches.
i. 3 4
0 1 2 3
4 5 6 7
8 9 10 11
ind=.{@({@i."0 @$)
ind i. 3 4
┌───┬───┬───┬───┐
│0 0│0 1│0 2│0 3│
├───┼───┼───┼───┤
│1 0│1 1│1 2│1 3│
├───┼───┼───┼───┤
│2 0│2 1│2 2│2 3│
└───┴───┴───┴───┘
i. 2 3 4
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
ind i. 2 3 4
┌─────┬─────┬─────┬─────┐
│0 0 0│0 0 1│0 0 2│0 0 3│
├─────┼─────┼─────┼─────┤
│0 1 0│0 1 1│0 1 2│0 1 3│
├─────┼─────┼─────┼─────┤
│0 2 0│0 2 1│0 2 2│0 2 3│
└─────┴─────┴─────┴─────┘
┌─────┬─────┬─────┬─────┐
│1 0 0│1 0 1│1 0 2│1 0 3│
├─────┼─────┼─────┼─────┤
│1 1 0│1 1 1│1 1 2│1 1 3│
├─────┼─────┼─────┼─────┤
│1 2 0│1 2 1│1 2 2│1 2 3│
└─────┴─────┴─────┴─────┘
Cheers, bob
> On Nov 13, 2020, at 09:05, thomas.bulka via Programming
> <[email protected]> wrote:
>
> Hi everyone,
>
> still learning J, I stumbled across a problem which should be easy to solve,
> but somehow I have not been able to do so, yet. Say, I have defined a matrix
> M:
>
> M =: 3 4 $ >: i. 12
>
> I now want to get the row and column index of 6 in M, which is 1 2. If M was
> a vector, I could easily get the index of 6 with the help of I.:
>
> I. 6 = , M
>
> Applying I. to M in its original shape, however, returns a boolean vector
> which indicates in which rows 6 has been found (at least that is my
> interpretation).
>
> Is it possible to apply I. to higher rank arrays in order to receive the
> complete indices of the elements I'm looking for? Or should I approach that
> problem in another way?
>
> Thank you very much in advance for your help!
>
> Kind regards,
>
> Thomas
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm