ind =. , # (#: i.@(*/))@$
   ind tst
0 3
2 0
3 3
5 0

(#: i.@(*/))  is the odometer function, supported by special code.

   ind2 =. $ #: I.@,
   ind2 tst
0 3
2 0
3 3
5 0

better for sparse operands (or maybe all operands, I haven't looked)

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Sherlock, Ric
> Sent: Wednesday, June 11, 2008 7:56 PM
> To: Programming forum
> Subject: [Jprogramming] find row and column indices
> 
> 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

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

Reply via email to