From: Ola Rinta-Koski
Subject: LOOP, MAXIMIZE all array columns?
Date: 
Message-ID: <x5d7a148bp.fsf@arenal.cyberell.com>
  If I have a 2-D array, is there an easy way of collecting the
  maximum values of each column using LOOP? MAXIMIZE works fine when
  the number of columns is fixed (and it's possible to explicitly code
  a MAXIMIZE instruction for each column), but I haven't been able to
  figure out what to do when it isn't.
-- 
        Ola Rinta-Koski                                 ···@cyberell.com
        Cyberell Oy                                     +358 41 467 2502
        Rauhankatu 8 C, FIN-00170 Helsinki, FINLAND	www.cyberell.com

From: Coby Beck
Subject: Re: LOOP, MAXIMIZE all array columns?
Date: 
Message-ID: <1BAF6.11481$482.54110@newsfeeds.bigpond.com>
"Ola Rinta-Koski" <···@cyberell.com> wrote in message
···················@arenal.cyberell.com...
>   If I have a 2-D array, is there an easy way of collecting the
>   maximum values of each column using LOOP? MAXIMIZE works fine when
>   the number of columns is fixed (and it's possible to explicitly code
>   a MAXIMIZE instruction for each column), but I haven't been able to
>   figure out what to do when it isn't.

Hi,

how about:
(loop for j below col
        collect (loop for i below row
                    maximize (aref array i j)))

as in

> (let ((col (+ 2 (random 5)))
          (row (+ 2 (random 5))))
      ;;make an array of pseudo-random dimensions
      (let ((array (make-array (list row col))))
      ;; fill with random numbers
        (dotimes (i row)
          (dotimes (j col)
            (setf (aref array i j) (random 50))))
        ;; print so we can visually verify
        (print array)
        ;; return the list of max values for each column
        (loop for j below col
            collect (loop for i below row
                        maximize (aref array i j)))))

#2A((28 8 26 29)
        (30 5 13 41)
        (33 13 33 43)
        (7 16 18 43))
(33 16 33 43)
>
...........
coby
From: Ola Rinta-Koski
Subject: Re: LOOP, MAXIMIZE all array columns?
Date: 
Message-ID: <x58zkp3uvy.fsf@arenal.cyberell.com>
"Coby Beck" <····@memetrics.com> writes:
> "Ola Rinta-Koski" <···@cyberell.com> wrote in message
> ···················@arenal.cyberell.com...
> >   If I have a 2-D array, is there an easy way of collecting the
> >   maximum values of each column using LOOP? MAXIMIZE works fine when
> >   the number of columns is fixed (and it's possible to explicitly code
> >   a MAXIMIZE instruction for each column), but I haven't been able to
> >   figure out what to do when it isn't.

> how about:
> (loop for j below col
>         collect (loop for i below row
>                     maximize (aref array i j)))

  Of course - thanks a lot...
-- 
        Ola Rinta-Koski                                 ···@cyberell.com
        Cyberell Oy                                     +358 41 467 2502
        Rauhankatu 8 C, FIN-00170 Helsinki, FINLAND	www.cyberell.com