comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Help with matrix operations
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Help with matrix operations [message #846] Thu, 29 April 1993 07:48 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
pln@egret0.Stanford.EDU (Patrick L. Nolan) writes:

> I have a little matrix problem that I'm trying to do without using
> loops. So far I'm not clever enough to figure out how to do it.
> Suppose we have
> A = fltarr(N,N)
> B = fltarr(N)
> C = fltarr(N,N,N)
> I want to have C(i,j,k) = A(i,j) + B(k)
> for all i,j,k < N. Is there a way to do this without writing
> ugly loops? I'm sure it's trivial, and I'll feel like a dope
> when the first person points it out. Fire away.

I don't think it's trivial. Here's how I would solve it.

; First expand A and B out to NxNxN arrays.
;
AA = A(*) # REPLICATE(1,N) ;AA is now (N*N, N) array
AA = REFORM(AA,N,N,N) ;Make it (N, N, N)
BB = REPLICATE(N*N) # B ;Do the same for B
BB = REFORM(BB,N,N,N)
C = AA + BB

I don't know if this is any more or less "ugly" than doing it in a loop, but it
should be much quicker. Of course you can combine all this into one command if
you want.

Bill Thompson
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: plotting vs year-month-day
Next Topic: Re: help for install IDL on Solris 2.1

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:42:31 PDT 2025

Total time taken to generate the page: 0.00418 seconds