Re: Array extraction, multiple slices from paired values [message #42421] |
Sun, 06 February 2005 04:43 |
Chris Lee
Messages: 101 Registered: August 2003
|
Senior Member |
|
|
In article <1107644491.108963.151620@f14g2000cwb.googlegroups.com>,
"MarioIncandenza" <ejhyer@gmail.com> wrote:
> Not what I wanted. See, each row of LOC is an XY pair corresponding to a
> location. So the 4x4xt output from the command in your post gives me the
> 4 time series I want, plus 12 others I don't want, and doesn't get me
> any closer to extracting them. I need to get 2-dimensional output. In
> loop form, this would work like this: WHAT_I_WANT = fltarr(NLOC,NT)
> for I=0,NLOC-1 do WHAT_I_WANT[I,*]=SUBDATA[LOC[0,I],LOC[1,I],*] Which
> works great, but that step is currently 75% of the total processor time
> for my script, which seems excessive, since it's not a processing step
> at all but a simple subset.
Hi,
If you want to access individual elements you have to explicitly index
all of the dimensions, to get the element pairs you want you need to
index the array as...
; data(nx, ny, nz)
; x(nr) & y(nr)
; res = data[x#replicate(1,nz), y#replicate(1,nz), replicate(1,nr)#lindgen(nz)]
The following shows it working with data(100,100,100) and x(100), y(100).
For these numbers you get a factor of 2 improvement. If you try and
subset data from an array with more than three dimensions, REPLICATE
won't work and you need REFORM & REBIN. (The 'i' loops are simply for
timing purposes)
nx=100 & ny=100 & nz=100 & nr=1000
data=randomu(100,nx,ny,nz)
x=long(randomu(200,nr)*nx)
y=long(randomu(300,nr)*ny)
res=fltarr(nr,nz)
t1=systime(1)
for i=0, 1000 do for j=0, nr-1 do res[j,*]=data[x[j],y[j],*]
t2=systime(1)
rz=replicate(1L,nz)
rr=replicate(1L,nr)
lz=lindgen(nz)
t3=systime(1)
for i=0, 1000 do res2=data[x#rz,y#rz,rr#lz]
t4=systime(1)
print, "Loop method: ",t2-t1
print, "Explicit index: ",t4-t3
;Chris
|
|
|
Re: Array extraction, multiple slices from paired values [message #42423 is a reply to message #42421] |
Sat, 05 February 2005 15:01  |
MarioIncandenza
Messages: 231 Registered: February 2005
|
Senior Member |
|
|
Not what I wanted. See, each row of LOC is an XY pair corresponding to
a location. So the 4x4xt output from the command in your post gives me
the 4 time series I want, plus 12 others I don't want, and doesn't get
me any closer to extracting them. I need to get 2-dimensional output.
In loop form, this would work like this:
WHAT_I_WANT = fltarr(NLOC,NT)
for I=0,NLOC-1 do WHAT_I_WANT[I,*]=SUBDATA[LOC[0,I],LOC[1,I],*]
Which works great, but that step is currently 75% of the total
processor time for my script, which seems excessive, since it's not a
processing step at all but a simple subset.
|
|
|
|