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

Home » Public Forums » archive » Re: zero-padding an array of arbitrary dimensionality (replacing execute in vm)
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: zero-padding an array of arbitrary dimensionality (replacing execute in vm) [message #54894] Thu, 19 July 2007 09:37 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Vince,

data=fltarr(43,45,23,12) ; <-- arbitrary
data[1,1,1,1]=1000. ; <-- so we know we get the right answer

tmp=size(data)
tmp=tmp[1:tmp[0]]
idx=1
for i=0,n_elements(tmp)-2 do idx=idx+product(tmp[0:i])

print,data[idx] ; We get element [1,1,1,1]

Helpful?

Probably doesn't work for 1D arrays.

Thanks,

Allan

hradilv wrote:
> I would like to zero-pad an array programmatically without knowing in
> advance what the dimensionality is of the array.
>
> For example, in 2D, for data = some fltarr (31,31) I could do
> dims = size(data,/dimensions)
> zpad = fltarr(dims[0]+1,dims[1]+1)
> zpad[1,1] = data
>
> For arb. dimensionality I have:
>
> dsize = size(data)
> ndim = dsize[0]
> dim = dsize[1:ndim]
> dtmp = make_array(dim+2,value=0,type=dsize[ndim+1])
>
> cmd = 'dtmp['
> for n=0L, ndim-1 do cmd = cmd+'1,'
> cmd = strmid(cmd,0,strlen(cmd)-1)+']=data'
> result = execute(cmd)
>
> But this won't work in the vm. So I need to somehow figure out the
> position of the [1,1,1,...] index for an arbitrary dimensionality.
>
> Clear enough? TIA!
> Vince
>
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: xrange woes
Next Topic: making DIALOG_MESSAGE jump out

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

Current Time: Sat Oct 11 12:23:05 PDT 2025

Total time taken to generate the page: 0.95742 seconds