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

Home » Public Forums » archive » Array indexing: what is IDL doing?
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
Array indexing: what is IDL doing? [message #60733] Fri, 06 June 2008 09:50
Conor is currently offline  Conor
Messages: 138
Registered: February 2007
Senior Member
So I want to pull out a small subsection from within a larger idl
array. I want to do something like this:

bigarr = findgen(500,100000)
bigx = [indgen(50)+100,indgen(25)+200]
bigy = indgen(10000)+50000

res = bigarr[bigx,bigy]

However IDL doesn't like that and says:

% All array subscripts must be same size. Var = BIGARR
% Execution halted at: $MAIN$

So I have to come up with another way to do it. My two thoughts were
the most straight forward way:

tarr = bigarr[bigx,*]
res = tarr[*,bigy]

and my other thought was to pre-build the indexes I want to extract,
and so I came up with this relatively simple command:

cx = n_elements(wx)
cy = n_elements(wy)
nx = n_elements(bigarr[*,0])
ind = transpose(rebin(wy,cy,cx))*nx + rebin(wx,cx,cy)
res = bigarr[ind]

I then wrote a little script to compare execution times, and I find
that if you are only extracting a small subsection (say, 500x10,000)
the index building method takes .04 seconds, compared to .11 seconds
for indexing bigarr twice. I'm really curious though why there's a
difference. Does it have something to do with using the asterix in
indexing? Is it just because it has two make two copies when I use
the first method? Since I'm extracting the same region either way,
I'd expect them to take about the same amount of time...
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: background color for draw widget
Next Topic: Re: not seeing the added values in widget_table?

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

Current Time: Fri Oct 10 22:27:22 PDT 2025

Total time taken to generate the page: 0.33636 seconds