Newsgroups: comp.lang.apl
Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!jtsv16!blister!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: Do I really need a loop?
Message-ID: <1991May15.134305.10894@yrloc.ipsa.reuter.COM>
Reply-To: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Organization: Iverson Software Inc.
References: <3970004@hpwrce.HP.COM> <15160018@hpdmd48.boi.hp.com>
Date: Wed, 15 May 91 13:43:05 GMT

Rudi Rynders) writes:

> Does anyone know how to do this other than writing a loop? Given a matrix
>                 M     =     1 2 3
>                             4 5 6
> and a vector 
>                 V     =     7 8
> I'd like to multiply 1 2 3 by 7, and multiply 4 5 6 by 8. In other words:
>                 1 2 3  x  7 
>                 4 5 6     8  
> The result will be
>                 7  14 21  
>                 32 40 48 
> Instead of writing a loop to do this, does APL have a more concise way?

And he writes subsequently,

> Sorry for the spurious previous responses, I flubbed with my editor.
> I would convert the vector V = 7 8 to a matrix the same size as M and
> fill it with a row of sevens and eigths as in VM assign 2 3 rho 7 7 7 8 8 8
> and then multiply M by VM to get the desired answer.

Alternatively, in J, one could write  M *"1 0 V  .  The rank conjunction 
(") modifies times (*) to work on rank 1 objects on the left and rank 0 
objects on the right; that is, multiply vectors of M by scalars of V.  

Alternatively, one could write  M *"_1 V  ; that is, multiply items of M 
by items of V.

-----------------------------------------------------------------
Roger Hui
Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
(416) 925 6096

