This seems like an underspecified problem. What do you mean by "more efficient"? (What resource is constrained?)
For example, are you looking for code golf [source code is the limiting resource] on this specific matrix? Are you trying to save memory? Are you trying to save time? These days, a machine with 64GB of memory is relatively easy to get access to. If you are working on problems where that's not enough to work on your dataset, you are going to need to get into a variety of machine-specific issues, but the starting step would be a good set of specifications on what you want to achieve. That said, if it's code golf, you could do something like this: D=: (+|:)>'';1.5;2 1.5;2.5 2 1.5 0 This relies on the use of two placeholders to help represent the full extent of the array, J's fill mechanism, and addition... Thanks, -- Raul On Tue, Oct 22, 2019 at 1:07 PM <[email protected]> wrote: > > Given a fully connected graph of n nodes. > The nodes are assigned indices i.n arbitrarily. > D is a distance matrix. Eg. > n =. 4 > ] D =. 4 4 $ 0 1.5 2 2.5 1.5 0 1.5 2 2 1.5 0 1.5 2.5 2 1.5 0 > > I'm not claiming this matrix fits in Euclidean geometry. > Nevertheless each element on the diagonal is 0 and > the matrix is symmetrical. > > Can anyone suggest a more efficient way to create the > matrix. Only (n * (n-1))%2 elements of D are unique. > Each unique elecment should be needed only once to build > the matrix. > > Thanks, Peter E. > > > > -- > https://en.wikibooks.org/wiki/Medical_Machines > Tel: +1 604 670 0140 Bcc: peter at easthope. ca > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
