Note that the row/column indices correspond to the decode of the
integer indices.

   3 4 #: 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

Likewise, the integer indices correspond to the encode of the
row/column indices:

   3 4 #. 3 4 #: i. 3 4
0 1  2  3
4 5  6  7
8 9 10 11

All that remains is to box the decoded indices, well, that and wrap
this in a verb which deals with the appropriate argument:

   bix=: <@#:"1 0  i.

That said, to answer your original question, if you want the row
indices in isolation, integer division will do the trick:

   <.(i.3 4)%4
0 0 0 0
1 1 1 1
2 2 2 2

But, anyways, there's a deep relation here, between polynomials,
number bases, and multidimensional array indices. For example,
consider the indices of a rank 3 array with dimension 10 10 10. The
integer index 543 corresponds to the boxed index <5 4 3, and this in
turn corresponds to the polynomial (3*x^0)+(4*x^1)+(5*x^2) with x=10.
In other words:

   3 4 5 p. 10
543

The real problem, though, thinking about this kind of thing, is that
it's all too simple, and we like to make things complicated.

Still, I hope this helps.

-- 
Raul


On Tue, Jan 10, 2017 at 6:05 PM, Skip Cave <[email protected]> wrote:
> Given a 3x4 matrix:
>
>
>
>   a =. i. 3 4
>
>   a
>
> 0 1  2  3
>
> 4 5  6  7
>
> 8 9 10 11
>
>
>
> I can get the horizontal indices:
>
>
>
>    4|a
>
> 0 1 2 3
>
> 0 1 2 3
>
> 0 1 2 3
>
>
>
>
>
> How do I get the vertical indices?
>
>
>
>   3?a   NB. The question-mark represents the unknown verb
>
> 0 0 0 0
>
> 1 1 1 1
>
> 2 2 2 2
>
>
>
> Ultimately, I want to design a verb bix, that will take a list of
> dimensions of any length, and generate boxed indices of the resulting
> array. The number of integers in each box will be the same as the rank of
> the array:
>
>
>
>
>   bix 10
>
> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
>
> │0│1│2│3│4│5│6│7│8│9│
>
> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
>
>
>
>   bix 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│
>
> └───┴───┴───┴───┘
>
>
>   bix 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│
>
> └─────┴─────┴─────┴─────┘
> ----------------------------------------------------------------------
> 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