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

Home » Public Forums » archive » Re: *replicate* but with arrays
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
Re: *replicate* but with arrays [message #26615] Mon, 10 September 2001 17:38 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark Hadfield (m.hadfield@niwa.cri.nz) writes:

> Check out JD Smith's Dimension Juggling Tutorial & Array Concatenation
> Tutorial, posted to this group in April or May this year. The following
> Google links *might* take you there
>
> http://groups.google.com/groups?as_umsgid=3AC7B345.1648F0A9% 40astro.cornell.
> edu
>
> http://groups.google.com/groups?q=Array+Concatenation+Tutori al&hl=en&group=c
> omp.lang.idl-pvwave&safe=off&rnum=1&selm=3AEF1FA 7.4ECBFB6%40astro.cornell.ed
> u

J.D. has given me permission to publish these tutorials on my
web page. This article jogged my memory that I hadn't done so
yet. But here they are now:

http://www.dfanning.com/tips/rebin_magic.html
http://www.dfanning.com/tips/array_concatenation.html

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: *replicate* but with arrays [message #26616 is a reply to message #26615] Mon, 10 September 2001 17:41 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
aqueous0123@yahoo.com (aqueous) writes:
> If I have array a[3,50] and array b[3], how do I fill all rows of a
> with the row vector b? For example, what I want to do is
>
> a = intarr(3,50)
> b = [6,5,4]
> a[0:2,*] = b ;or a[*,*] = b
>
> a should now look like
>
> [6,5,4]
> [6,5,4]
> [6,5,4]
> [6,5,4]
> ...
>
> I thought I could use replicate or makearray, like..
> a = REPLICATE(b, n_elements(b), 50)
> or
> a = MAKE_ARRAY(n_elements(b), 50, /INTEGER, VALUE= b)

Mark and Pavel's responses are fine and dandy. I use REBIN all the
time to do exactly the kind of thing you are after. However, if you
just want a REPLICATE work-alike, then I might suggest the function
CMREPLICATE, available from my web page.

It is standalone and works just like you'd expect, even simpler
actually since you don't specify n_elements(b):

IDL> b = [6,5,4]
IDL> a = cmreplicate(b, 50)
IDL> help, a
A INT = Array[3, 50]

For numeric arrays it uses rebin so it is just as efficient as using
REBIN yourself. However it also works generally on structure arrays
and strings, which are processed differently.

Good luck,
Craig

http://cow.physics.wisc.edu/~craigm/idl/idl.html (under Arrays)

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: *replicate* but with arrays [message #26618 is a reply to message #26615] Mon, 10 September 2001 15:15 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Try
a = rebin(b, 3, 50)
Cheers,
Pavel

aqueous wrote:
>
> If I have array a[3,50] and array b[3], how do I fill all rows of a
> with the row vector b? For example, what I want to do is
>
> a = intarr(3,50)
> b = [6,5,4]
> a[0:2,*] = b ;or a[*,*] = b
>
> a should now look like
>
> [6,5,4]
> [6,5,4]
> [6,5,4]
> [6,5,4]
Re: *replicate* but with arrays [message #26619 is a reply to message #26618] Mon, 10 September 2001 15:15 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Check out JD Smith's Dimension Juggling Tutorial & Array Concatenation
Tutorial, posted to this group in April or May this year. The following
Google links *might* take you there

http://groups.google.com/groups?as_umsgid=3AC7B345.1648F0A9% 40astro.cornell.
edu

http://groups.google.com/groups?q=Array+Concatenation+Tutori al&hl=en&group=c
omp.lang.idl-pvwave&safe=off&rnum=1&selm=3AEF1FA 7.4ECBFB6%40astro.cornell.ed
u

But to cut a long story short, my preferred way to do what you want is

b = [6,5,4]
a = rebin(b,n_elements(b),50)

Here rebin is trying to expand the second dimension of b to 50. Since b
doesn't have a second dimension it creates one with size 1, then fills it by
replication.

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: *replicate* but with arrays
Next Topic: compiling before needing

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

Current Time: Tue Oct 21 00:17:49 PDT 2025

Total time taken to generate the page: 3.60032 seconds