http://rosettacode.org/wiki/Matrix_transposition#Clojure
Does anyone know if transpose exists in core or contrib? A cursory check doesn't reveal it, seems like it should be available. Thanks On Thu, Apr 8, 2010 at 10:27 PM, Per Vognsen <per.vogn...@gmail.com> wrote: > Or you can separate concerns a bit more: > > (defn transpose [xs] > (apply map vector xs)) > > Now Nurullah's original suggestion applies: > > (map #(apply max %) (transpose xs)) > > -Per > > On Fri, Apr 9, 2010 at 12:38 AM, James Reeves > <weavejes...@googlemail.com> wrote: > > On Apr 8, 1:13 pm, John Sanda <john.sa...@gmail.com> wrote: > >> [ > >> [1 2 3] > >> [2 5 1] > >> [4 2 6] > >> ] > >> > >> I am comparing the values in each of the columns, so the result should > be [4 > >> 5 6] where the first element represents the largest value in the first > >> column, the second element represents the largest value in the second > >> column, etc. > > > > The `map` function allows you to specify more than one collection. > > With multiple collections, the mapping function is passed an argument > > for each collection. So: > > > > (map + [1 2 3] [4 5 6]) > > => ((+ 1 4) (+ 2 5) (+ 3 6)) > > => (5, 7, 9) > > > > By combining this with `apply` and `max`, you can find the maximum > > value of each column: > > > > (defn max-columns [coll] > > (apply map max coll)) > > > > If we pass your vector to max-columns: > > > > (max-columns [[1 2 3] [2 5 1] [4 2 6]]) > > => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) > > => (map max [1 2 3] [2 5 1] [4 2 6]) > > => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) > > => (4 5 6) > > > > - James > > > > -- > > 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<clojure%2bunsubscr...@googlegroups.com> > > For more options, visit this group at > > http://groups.google.com/group/clojure?hl=en > > > > To unsubscribe, reply using "remove me" as the subject. > > > > -- > 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<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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