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

Home » Public Forums » archive » Adding arrays of different dimensions
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Adding arrays of different dimensions [message #56431] Fri, 19 October 2007 09:46
ianpaul.freeley is currently offline  ianpaul.freeley
Messages: 18
Registered: March 2007
Junior Member
I keep running into this and not being sure what the best solution is.

I have a 2d array, and I'd like to add a 1d array to each row (or
column).
The easy stupid slow way:
a=findgen(3,5)
b=[1,2,3]
for i=0,4 do a[*,i]=a[*,i]+b

Perhaps a better way with no loops:
a=findgen(3,5)
b=[1,2,3]
x=b#(fltarr(n_elements(a[0,*])) +1)
a=a+x

Is there a better way? Anyone care to generalize so I can optimally
add 2d arrays into 3d?


Thanks,
IP Freeley
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Widget Definition from the Event Handler?
Next Topic: Re: Adding arrays of different dimensions

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

Current Time: Wed Oct 08 19:14:21 PDT 2025

Total time taken to generate the page: 0.00386 seconds