I2d =: $ ((] <.@% 1{[) <"1@,. ] |~ 1 { [) I.@, NB. returns I. (of 1s) but in 2d
index format
I2d a
┌───┬───┬───┬───┬───┐
│0 0│2 3│4 6│6 9│9 2│
└───┴───┴───┴───┴───┘
A boxed result helps because it can be used as argument for { }
________________________________
From: Skip Cave <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Friday, November 30, 2018 1:52 PM
Subject: [Jprogramming] Array Coordinates
Given the array a:
]a=.10 10$0=23|i.100
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
How can I write a function 'ac' that will list the coordinates of each 1 in
the array?
Example using array a:
ac a
0 0
2 3
4 6
6 9
9 3
Extend to 3 or more dimensions?
Skip Cave
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm