Each time access different part of an array [message #94562] |
Thu, 06 July 2017 10:44  |
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  |
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
|
|
|