[Jprogramming] Indices of a matrix
Ben Gorte - CITG
B.G.H.Gorte at tudelft.nl
Tue Jan 10 23:11:32 UTC 2017
How about:
4$.$. i.3 4
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
2 3
4$.$. i.2 3 4
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
(thanks to Marshall Lochbaum iirc)
Ben
_______________________________________
From: Programming [programming-bounces at forums.jsoftware.com] on behalf of Skip Cave [skip at caveconsulting.com]
Sent: Wednesday, January 11, 2017 00:05
To: Programming at jsoftware.com
Subject: [Jprogramming] Indices of a matrix
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
More information about the Programming
mailing list