In separate thread I needed to find the row and column indices of 1s in a 
rectangular array.

tst=: _99&".;._2 (0 : 0)
0 0 0 1 0 0
0 0 0 0 0 0
1 0 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 0
1 0 0 0 0 0
)

  indices tst
0 3
2 0
3 3
5 0

I came up with the following but feel I'm probably missing something (much) 
simpler?

indices=: (1 , {:@$) *"1 [: (<. ,. 1&|) {:@$ %~ [: I. ,

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to