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 #54985 is a reply to message #54894] Thu, 19 July 2007 15:11 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Jul 19, 10:37 am, Allan Whiteford
<allan.rem...@phys.remove.strath.ac.remove.uk> wrote:
> 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]]

This is easier:

tmp = size(data, /dimensions)

> 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?

That calculates the index, but I don't see how to use that. A straight-
forward

data[idx] = origArray

doesn't seem to work. Am I missing some other way to copy the original
array into the padded array?

It's ugly, but I think this should do the trick:

function zeropad, arr
compile_opt strictarr
on_error, 2

ndims = size(arr, /n_dimensions)
if (ndims lt 1) then message, 'must be an array'

padded = make_array(dimension=size(arr, /dimensions) + 2L, $
type=size(a, /type))
case ndims of
1 : padded[1] = arr
2 : padded[1, 1] = arr
3 : padded[1, 1, 1] = arr
4 : padded[1, 1, 1, 1] = arr
5 : padded[1, 1, 1, 1, 1] = arr
6 : padded[1, 1, 1, 1, 1, 1] = arr
7 : padded[1, 1, 1, 1, 1, 1, 1] = arr
8 : padded[1, 1, 1, 1, 1, 1, 1, 1] = arr
endcase

return, padded
end

Mike
--
www.michaelgalloy.com
[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: Sun Oct 12 14:53:45 PDT 2025

Total time taken to generate the page: 1.67919 seconds