At 11:32 AM 5/30/2001 -0600, James Giles wrote:
>"Anthony Stone" <[log in to unmask]> wrote:
>
> > I would like to be able to assign the outer product of two arrays to a
> > third:
> > a(1:5,1:8)=b(1:5)*c(1:8)
> > There seems to be no way to do this without using a do loop over one
> > of the indices. Is that correct? I am aware that such a construction
> > would be ambiguous in a case like
> > a(1:4,1:4)=b(1:4)*c(1:4)
> > though even here there is an 'obvious' interpretation.
>
>Look up the FORALL construct. You should be able
>to write:
>
>FORALL (I = 1:5, J = 1:8) A(I,J) = B(I) * C(J)
Or use SPREAD:
a=spread(b,2,size(c))*spread(c,1,size(b))
[I probably would use the FORALL unless I were using an f90 compiler that
wasn't yet upgraded to f95, but this does illustrate that there are often
multiple ways to approach array computation in Fortran 90/95.]
--
Kurt W Hirchert [log in to unmask]
UIUC Department of Atmospheric Sciences +1-217-265-0327
|