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

Home » Public Forums » archive » Re: REPLICATE with arrays
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: REPLICATE with arrays [message #18896 is a reply to message #18884] Fri, 11 February 2000 00:00 Go to previous messageGo to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Vince Hradil <hradilv@yahoo.com> writes:

> I often have the need to replicate an array, but IDL's replicate only
> works with scalars. Does anyone have any tips on the most efficient,
> simplest, clearest (you choose) way to do this?

> e.g.

> I have:
> help, x
> INT = Array[3, 3]
> print, x
> 2 4 10
> 3 7 5
> 3 9 2

> and would like to do:
> x2 = replicate(x,2)
> help, x2
> INT = Array[3, 3, 2]
> print, x2
> 2 4 10
> 3 7 5
> 3 9 2

> 2 4 10
> 3 7 5
> 3 9 2

> I've figured out some trick for 1 and 2 dimensional arrays, but I'm
> looking for a more general strategy to use on higher dim arrays.

Stein Vidar Haugan once proposed the following strategy which appears to be
highly efficient:

x2 = rebin( reform(x,3,3,1), 3,3,2)

If one always wants the replication dimension to be the last dimension, then
the following should be a good way of generalizing it:

sz = size(x)
dim = sz[1:sz[0]]
x2 = reform(x,[dim,1])
case n_elements(dim) of
1: x2=rebin(x2,dim(0),n)
2: x2=rebin(x2,dim(0),dim(1),n)
3: x2=rebin(x2,dim(0),dim(1),dim(2),n)
4: x2=rebin(x2,dim(0),dim(1),dim(2),dim(3),n)
5: x2=rebin(x2,dim(0),dim(1),dim(2),dim(3),dim(4),n)
6: x2=rebin(x2,dim(0),dim(1),dim(2),dim(3),dim(4),dim(5),n)
7: x2=rebin(x2,dim(0),dim(1),dim(2),dim(3),dim(4),dim(5),dim(6) ,n)
endcase

William Thompson
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL 5.3 on NT newbie annoyances
Next Topic: Re: Writing formatted text files

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

Current Time: Sat Oct 11 16:17:24 PDT 2025

Total time taken to generate the page: 1.68093 seconds