You need to regenerate rows and cols to match the matrix size you are
working with:

      'row col'=. |:3 4 #:,i.3 4
      pairs =: [: ,/ [: (2 ,/\ ])"1 (, |:)

      pairs i. 3 3
0 1
1 2
3 4
4 5
6 7
7 8
0 3
3 6
1 4
4 7
2 5
5 8

FYI,

-- 
Raul

On Wed, Mar 6, 2013 at 3:24 PM, Zsbán Ambrus <[email protected]> wrote:
> On 2/24/13, km <[email protected]> wrote:
>>     pairs =: [: ,/ [: (2 ,/\ ])"1 (, |:)  NB. Constructs left-right and
>> up-down arcs
>>     pairs i. 3 3  NB. left-right and up-down arcs
>
> This is a nice trick to create the list of edges.  However, it doesn't
> work for a non-square matrix.  For example, (pairs i. 3 4) will
> contain the edge (9 0) which shouldn't really be there.
>
>>     CM=: #. e.~ [: i. [ , [  NB. Borrowed from 20. Directed Graphs in
>> Dictionary
>
> I find this method of converting the list to the adjacency matrix
> strange.  I would instead use the amend verb, like this:
>
>    CM =: (1:`(<"1@[)`]} 0$~,~)~
>
> Ambrus
> ----------------------------------------------------------------------
> 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