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

Home » Public Forums » archive » Re: Replicate array over columns - using transpose?
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 array over columns - using transpose? [message #79680] Fri, 23 March 2012 05:06
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
I don't think this variant is covered yet:

a = reform(float([10,35,60,85,110]), 1, 5, /overwrite)
print, rebin(a, 4, 5)

--
Yngvar
Re: Replicate array over columns - using transpose? [message #79693 is a reply to message #79680] Thu, 22 March 2012 08:18 Go to previous message
Russell[1] is currently offline  Russell[1]
Messages: 101
Registered: August 2011
Senior Member
On Mar 22, 8:01 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
> On Thursday, March 22, 2012 6:11:54 AM UTC-4, robintw wrote:
>> Hi all,
>
>> I've got an array, a, as follows:
>
>> IDL> print, a
>>        10.0000      35.0000      60.0000      85.0000      110.000
>
>> I want to replicate this across 4 columns to produce an array like the
>> following:
>
>> 10 10      10      10
>> 35 35      35      35
>> 60 60      60      60
>> 85 85      85      85
>> 110        110     110     110
>
>> I'm using the CMREPLICATE routine to do this, and get the following:
>
>> IDL> print, CMREPLICATE(a, 4)
>>        10.0000      35.0000      60.0000      85.0000      110.000
>>        10.0000      35.0000      60.0000      85.0000      110.000
>>        10.0000      35.0000      60.0000      85.0000      110.000
>>        10.0000      35.0000      60.0000      85.0000      110.000
>
>> However, I want to replicate it in the columns as in the example above.
>> As far as I can see it there are two ways to deal with this: transpose
>> the array after I've done it (computationally expensive, as I'll be
>> doing it with far larger arrays in the real program) or transpose it
>> before running CMREPLICATE. However, if I do this I get an extra
>> dimension added:
>
>> IDL> help, CMREPLICATE(transpose(a), 4)
>> <Expression>    FLOAT     = Array[1, 5, 4]
>
>> Is there a way to replicate over the columns without adding this extra
>> dimension? I'm sure I'm missing something simple here.
>
> I'm the CM in CMreplicate, but I wouldn't use CMreplicate.  I use this instead.
>
> print, [1,1,1,1,1] # a
>
> Usually I'm matching up X and Y labels to a 2D grid, so I do this,
>
>   XX = (X*0 + 1) # Y
>   YY = X # (Y*0 + 1)
>
> Now XX and YY are 2D arrays with X running along one axis and Y running along the other axis.  It looks crazy, but it works.
>
> Craig

Ha! I should have read on. I didn't see someone posted this answer.

Sorry for the repetition,
Russell
Re: Replicate array over columns - using transpose? [message #79694 is a reply to message #79693] Thu, 22 March 2012 08:17 Go to previous message
Russell[1] is currently offline  Russell[1]
Messages: 101
Registered: August 2011
Senior Member
It's way easier than that.

Suppose,
a=[10,35,60,85,110.]

and you want it to have n entries, then all you need is


b=(1+bytarr(n))#a


voila!

Russell


On Mar 22, 6:11 am, Robin Wilson <ro...@rtwilson.com> wrote:
> Hi all,
>
> I've got an array, a, as follows:
>
> IDL> print, a
>        10.0000      35.0000      60.0000      85.0000      110.000
>
> I want to replicate this across 4 columns to produce an array like the
> following:
>
> 10      10      10      10
> 35      35      35      35
> 60      60      60      60
> 85      85      85      85
> 110     110     110     110
>
> I'm using the CMREPLICATE routine to do this, and get the following:
>
> IDL> print, CMREPLICATE(a, 4)
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>
> However, I want to replicate it in the columns as in the example above.
> As far as I can see it there are two ways to deal with this: transpose
> the array after I've done it (computationally expensive, as I'll be
> doing it with far larger arrays in the real program) or transpose it
> before running CMREPLICATE. However, if I do this I get an extra
> dimension added:
>
> IDL> help, CMREPLICATE(transpose(a), 4)
> <Expression>    FLOAT     = Array[1, 5, 4]
>
> Is there a way to replicate over the columns without adding this extra
> dimension? I'm sure I'm missing something simple here.
>
> Cheers,
>
> Robin
Re: Replicate array over columns - using transpose? [message #79695 is a reply to message #79694] Thu, 22 March 2012 05:01 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Thursday, March 22, 2012 6:11:54 AM UTC-4, robintw wrote:
> Hi all,
>
> I've got an array, a, as follows:
>
> IDL> print, a
> 10.0000 35.0000 60.0000 85.0000 110.000
>
> I want to replicate this across 4 columns to produce an array like the
> following:
>
> 10 10 10 10
> 35 35 35 35
> 60 60 60 60
> 85 85 85 85
> 110 110 110 110
>
> I'm using the CMREPLICATE routine to do this, and get the following:
>
> IDL> print, CMREPLICATE(a, 4)
> 10.0000 35.0000 60.0000 85.0000 110.000
> 10.0000 35.0000 60.0000 85.0000 110.000
> 10.0000 35.0000 60.0000 85.0000 110.000
> 10.0000 35.0000 60.0000 85.0000 110.000
>
> However, I want to replicate it in the columns as in the example above.
> As far as I can see it there are two ways to deal with this: transpose
> the array after I've done it (computationally expensive, as I'll be
> doing it with far larger arrays in the real program) or transpose it
> before running CMREPLICATE. However, if I do this I get an extra
> dimension added:
>
> IDL> help, CMREPLICATE(transpose(a), 4)
> <Expression> FLOAT = Array[1, 5, 4]
>
> Is there a way to replicate over the columns without adding this extra
> dimension? I'm sure I'm missing something simple here.

I'm the CM in CMreplicate, but I wouldn't use CMreplicate. I use this instead.

print, [1,1,1,1,1] # a

Usually I'm matching up X and Y labels to a 2D grid, so I do this,

XX = (X*0 + 1) # Y
YY = X # (Y*0 + 1)

Now XX and YY are 2D arrays with X running along one axis and Y running along the other axis. It looks crazy, but it works.

Craig
Re: Replicate array over columns - using transpose? [message #79696 is a reply to message #79695] Thu, 22 March 2012 04:42 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Thu, 22 Mar 2012 12:25:52 +0100, Heinz Stege wrote:
>
> help,transpose(rebin(a,n_elements(a),4,/sample))

Don't use the above. Lajos' solution without the TRANSPOSE operation
is much more efficient:

On Thu, 22 Mar 2012 03:50:39 -0700 (PDT), Lajos Foldy wrote:
>
> b=rebin(reform(a,1,5), 5,5)

Heinz
Re: Replicate array over columns - using transpose? [message #79697 is a reply to message #79696] Thu, 22 March 2012 04:25 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
Hi Robin,

I don't know CMREPLICATE. Does the following work?

help,transpose(cmreplicate(a,4))

Another question: What is the advantage of using CMREPLICATE instead
of the built-in REBIN function?

help,transpose(rebin(a,n_elements(a),4,/sample))

Heinz
Re: Replicate array over columns - using transpose? [message #79698 is a reply to message #79697] Thu, 22 March 2012 03:57 Go to previous message
dplatten is currently offline  dplatten
Messages: 32
Registered: December 2007
Member
Hi Robin,

You can use a combination of REBIN and TRANSPOSE to do this. The following should work for you:

nElements = 5
nCols = 4

test = INDGEN(nElements)
print, test
0 1 2 3 4

print, REBIN(TRANSPOSE(test), nCols, nElements)
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4

Regards,

David
Re: Replicate array over columns - using transpose? [message #79699 is a reply to message #79698] Thu, 22 March 2012 03:50 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Mar 22, 11:11 am, Robin Wilson <ro...@rtwilson.com> wrote:
> Hi all,
>
> I've got an array, a, as follows:
>
> IDL> print, a
>        10.0000      35.0000      60.0000      85.0000      110.000
>
> I want to replicate this across 4 columns to produce an array like the
> following:
>
> 10      10      10      10
> 35      35      35      35
> 60      60      60      60
> 85      85      85      85
> 110     110     110     110
>
> I'm using the CMREPLICATE routine to do this, and get the following:
>
> IDL> print, CMREPLICATE(a, 4)
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>        10.0000      35.0000      60.0000      85.0000      110.000
>
> However, I want to replicate it in the columns as in the example above.
> As far as I can see it there are two ways to deal with this: transpose
> the array after I've done it (computationally expensive, as I'll be
> doing it with far larger arrays in the real program) or transpose it
> before running CMREPLICATE. However, if I do this I get an extra
> dimension added:
>
> IDL> help, CMREPLICATE(transpose(a), 4)
> <Expression>    FLOAT     = Array[1, 5, 4]
>
> Is there a way to replicate over the columns without adding this extra
> dimension? I'm sure I'm missing something simple here.
>
> Cheers,
>
> Robin

b=rebin(reform(a,1,5), 5,5)

regards,
Lajos
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: external string EXP for MATH_DOIT (ENVI)
Next Topic: Coyote graphics and resizeable draw widgets

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

Current Time: Wed Oct 08 18:52:32 PDT 2025

Total time taken to generate the page: 0.00581 seconds