I think I see what you are doing. I'd like to suggest an alternate representation - I think it would make this a lot easier.
society=: 4 6;'';'';0 1;1 6;1;7;4 Here, I've done several things: (*) I've gotten rid of the 1 2 3 4 5 6 7 8 values. They are implied by the structure of the the list. I see no reason to go to extra effort to represent the indices of the array as a part of the array. (*) I've discarded the _. values. In my opinion, they were there as place holders so that you would not lose your index values. But you were in no danger of losing something that was already there. Also, why use Not a Number when you can use nothing? (*) I've subtracted 1 from each of the remaining values. Now we can convert this to a connection matrix and back: s2cm=: <@i.@# e.&> ] cm2s=: <@I. But a note of caution: there's a shape difference that can show up here. society-: ,each cm2s s2cm society 0 (,each society)-: cm2s s2cm society 1 society= cm2s s2cm society 1 1 1 1 1 0 0 0 The last three boxes contain dimensionless structures and when comparing boxes, J makes a distinction between the value by itself and the list of one element which contains only that value. Perhaps that's not a big deal to you, but it's simple to work around if you care. Anyways, once we have that we can do this: cm2s (+. |:) s2cm society ┌─────┬─────┬┬───┬───────┬─┬─────┬───┐ │3 4 6│3 4 5││0 1│0 1 6 7│1│0 4 7│4 6│ └─────┴─────┴┴───┴───────┴─┴─────┴───┘ This result is of course in a different format than your symSoc, but I'm hoping that those differences are irrelevant for you. (I've removed the _. entries, and I've lost the ordering of the values, but I don't think either of those should carry meaning.) Here's how to make that result look closer to your symSoc: >:each(i.@# ,.each ])cm2s (+. |:) s2cm society I've lost some information, here - but if that information represented noise, losing it should be a good thing. Thanks, -- Raul On Wed, Oct 9, 2013 at 9:21 PM, elton wang <[email protected]> wrote: > Thanks Raul, > write it in one line, and remove both my verb find and unique: > > society =. (1 ,. 5 7); (2 ,. _.);(3 ,. _.); (4 ,. 1 2); (5 ,. 2 7);(6 ,. > 2);(7 ,. 8) ;(8 ,. 5) > > ]symSoc =. society , L:0 (<"0 q) ,.L:0 ({.p) #~ L:0 (({:p)&e. each (q =. > ~.{.p =. |:;society)) > > > The key verbs above are e. each, and # only for finding matches. All others > are just formatting. > > > > > > On Wednesday, October 9, 2013 5:05 PM, Raul Miller <[email protected]> > wrote: > > The J dictionary uses 'nub' to describe an operation which behaves > like your 'unique', here. > > http://www.jsoftware.com/help/dictionary/d221.htm > > I hope this helps. (And I must admit I didn't notice anything else > that I'd change.) > > -- > Raul > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
