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

Home » Public Forums » archive » Subscripting help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Subscripting help [message #92206] Thu, 29 October 2015 07:44 Go to previous message
khyde is currently offline  khyde
Messages: 21
Registered: November 2013
Junior Member
Hello,

I need to convert a large 2D array to a smaller 1D array by taking the mean of several pixels in the 2D array before putting them into known locations in the 1D array (or bin). The challenge is that the number of pixels per bin varies so I don't know how to do it without creating a large loop. I was hoping there was a way I could do it with subscripts, but I haven't been able to figure it out yet.

Here is an example of what I want to do using a loop. It works fine for this example, but my real 2D array is 8640x4320 and I need to move it to a ~5.6 million 1D array and it would take days to run it in a loop.

ARR_2D = FINDGEN(9,10) ; Input 2D array
ARR_1D = FLTARR(18) ; Output 1D array (bins)

; MAKE UP SUBSCRIPTS FOR THE ARRAY TO FIT INTO THE BINS (KNOWN BIN LOCATIONS)
SUBS = LONG(ARR_2D)
S = [REVERSE(INDGEN(9)+1),INDGEN(9)+1]
FOR N=0, N_ELEMENTS(S)-1 DO BEGIN
IF N EQ 0 THEN FSUB = 0 ELSE FSUB = LSUB
IF N EQ 0 THEN LSUB = S(N)-1 ELSE LSUB = FSUB + S(N)
SUBS(FSUB:LSUB) = N
ENDFOR


; LOOP METHOD
FOR N=0, N_ELEMENTS(ARR_1D)-1 DO BEGIN
OK = WHERE(SUBS EQ N, COUNT)
IF COUNT GE 1 THEN ARR_1D(N) = MEAN(ARR_2D(OK))
ENDFOR

PRINT, ARR_2D
PRINT
PRINT, ARR_1D

Is there a faster way to get the same results? I was trying to figure out a way to do it with subscripts, but haven't had much success.

Thanks for your input.
Kim
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Histogram within a colorbar
Next Topic: Read data from file

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

Current Time: Wed Oct 08 09:07:49 PDT 2025

Total time taken to generate the page: 0.02253 seconds