On Dec 3, 4:28 am, Tiemo Kieft <t.ki...@gmail.com> wrote: > Hi, > > I'm trying to create a matrix, basically it's a vector of vectors. I copied > the code from ants.clj to create the matrix, however, I have to mirror the > matrix around it's main diagonal (see below). Currently I'm doing this by > first creating the matrix like this: > (apply vector (map (fn [i] > (apply vector (map (fn [j] j) n))) n)))))) > > Where n is a range. After doing this I basically repeat the same thing, now > mirroring the matrix around it's main diagonal. While this works, it's ugly > and inefficient, and I'm wondering if there is a better of way of doing this. > Below is a diagram of how it should look. > > | 1 | 2 | 3 | > ---------------- > 1 | 0 | A | B | > ---------------- > 2 | A | 0 | C | > ---------------- > 3 | B | C | 0 | > ---------------- > > The 0's on the diagonal just mean that the diagonal is ignored, A, B and C > are ref's. > > - Tiemo.
Perhaps I'm misapprehending the issue, but why isn't the following sufficient: (defn transpose [matrix] (vec (apply map vector m))) (transpose [[1 2] [3 4]]) [[1 3] [2 4]] -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en