Re: Sum to Arrays [message #4309 is a reply to message #4243] |
Tue, 23 May 1995 00:00   |
mole
Messages: 5 Registered: April 1995
|
Junior Member |
|
|
Stein Vidar Hagfors Haugan (steinhh@amon.uio.no) wrote:
: In article <moleD8uArz.DFG@netcom.com>, mole@netcom.com (Aaron Birenboim) writes:
: [...stuff deleted...]
: |>
: |> OK.... here's a tougher one to vectorize...
: |>
: |>
: |> I want CENTROIDS, FAST!!! I'm stuck with :
: |>
: |> x = fltarr(m)
: |> for i=0,n do x = TOTAL(y(*,i) * findgen(n+1))
: |>
oops... I meant:
x = fltarr(n)
for i=0,n-1 do x(i) = TOTAL(y(*,i) * findgen(m))
get the idea? Weight each column of y by its index and then total
also... I'm trying to be portable between PV-Wave and IDL, so I cannot
use the 2 argument total. (I just found that out)
: Anyway, here are centroids for you:
: Given e.g., I(x,y), an M x N array:
: X = REBIN(REFORM(FINDGEN(M),M,1,/OVERWRITE),M,N,/SAMPLE) ; Gives you X(x,y)
neat. I doubt I'd have come up with that.
: CTROIDS_X = TOTAL(I*X,1)/TOTAL(I,1) ; Gives an array of the centroids
: ; (the X centroid at each y index.)
: CTROID_X = TOTAL(I*X)/TOTAL(I) ; Gives the X Centroid coordinate
: ; of the whole array.
: ;------------ or, for Y centroids...
thanks.
--
Aaron Birenboim | 1007 Pampas Dr. SE |
mole@netcom.com | Albuquerque, NM 87108 |
(505) 254-1749 | |
(505) 247-8371 (w) or birenboi@ataway.aptec.com |
|
|
|