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

Home » Public Forums » archive » Re: Adding arrays of different dimensions
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: Adding arrays of different dimensions [message #56429 is a reply to message #56427] Fri, 19 October 2007 10:17 Go to previous messageGo to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
ianpaul.freeley@gmail.com wrote:
> 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

Xsize = 2
Ysize = 3
Zsize = 4

a = indgen(Xsize, Ysize)
b = indgen(Xsize) + 1
print, a + rebin(b,Xsize, Ysize)

or in 3D:
a = indgen(Xsize, Ysize,Zsize)
b = indgen(Xsize,Ysize) + 1
print, a + rebin(b,Xsize, Ysize,Zsize)
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Adding arrays of different dimensions
Next Topic: Using IDL from a perl script

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

Current Time: Sat Oct 11 15:23:43 PDT 2025

Total time taken to generate the page: 0.72057 seconds