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

Home » Public Forums » archive » Each time access different part of an array
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
Each time access different part of an array [message #94562] Thu, 06 July 2017 10:44 Go to next message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
Hi,

I have a 1D array with an odd number of rows, e.g. A=indgen(2435).

I want to split the array A into two parts and first access the entries A[0:1217] and then A[1218:*].

Then I would like to split my array into 4 parts and access each part every time.
Then split the matrix into 8 parts and so on.

Can anyone help with that?

Thanks in advanced.
Re: Each time access different part of an array [message #94567 is a reply to message #94562] Mon, 10 July 2017 06:39 Go to previous message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 07/06/2017 07:44 PM, dmfl0590@gmail.com wrote:
> I have a 1D array with an odd number of rows, e.g. A=indgen(2435).
>
> I want to split the array A into two parts and first access the entries A[0:1217] and then A[1218:*].
>
> Then I would like to split my array into 4 parts and access each part every time.
> Then split the matrix into 8 parts and so on.

A=indgen(2435)
dd=ceil(alog2(n_elements(A)))
ll=lonarr(2^dd*2,2)
ll[1,1]=n_elements(A)-1
for j=1,dd do begin & $
ll[2^j :2^j*2-1:2,0]=ll[2^j/2:2^j-1,0] & $
ll[2^j+1:2^j*2-1:2,0]=ll[2^j/2:2^j-1,0] $
+(ll[2^j/2:2^j-1,1]+1-ll[2^j/2:2^j-1,0])/2 & $
ll[2^j :2^j*2-1:2,1]=ll[2^j/2:2^j-1,0] $
+(ll[2^j/2:2^j-1,1]+1-ll[2^j/2:2^j-1,0])/2-1 & $
ll[2^j+1:2^j*2-1:2,1]=ll[2^j/2:2^j-1,1] & $
endfor

; just for demonstration purposes print indices
for j=0,5 do print, ll[2^j :2^j*2-1,*], $
format='(2('+string(2^j,format='(i0)')+'i' $
+string(5*2^(5-j),format='(i0)')+',"'+string(10b)+'"))'

; ll can then be used to index A

a1=A[ll[1,0]:ll[1,1]]
a2=A[ll[2,0]:ll[2,1]]
a3=A[ll[3,0]:ll[3,1]]

I hope that helps, however using the divide & conquer strategy is better
done in a lower level language than IDL.

Good luck anyway, Markus

ps: When your array has more than 32767 elements, use
COMPILE_OPT idl2 or COMPILE_OPT DEFINT32
or replace all 2 by 2l
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem creating .png file using Coyote graphics (or maybe problem with cgHasImageMagick?)
Next Topic: GeoTIFF help - conversion to lat/lon

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

Current Time: Wed Oct 08 07:16:22 PDT 2025

Total time taken to generate the page: 0.00468 seconds