[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help setting up an array
> Now, what I want to be able to do is re-bin these points into an
> n-dimensional discretized space array which encloses all points. I can
You mean something like this? I'm sure there are many ways to do it.
pro thorne, x, w, box
;x[ndim, npts]
;w[npts]
npts = n_elements(x[0,*])
ndim = n_elements(x[*,0])
xmin = fltarr(ndim)
xmax = fltarr(ndim)
dx = fltarr(ndim)
for i = 0, ndim-1 do begin
xmin[i] = min(x[i,*])
xmax[i] = max(x[i,*])
endfor
dx[*] = 1. ;how is this determined?
ngrid = ceil( (xmax - xmin) / dx + 1.e-4 )
ibox = lonarr(npts)
nmult = 1
for i = 0, ndim-1 do begin
ibox = ibox + nmult * fix( ( x[i,*] - xmin[i] ) / dx[i] )
nmult = nmult * ngrid[i]
endfor
;this could be improved with histogram?
box = fltarr(nmult)
for j = 0, npts-1 do begin
box[ibox[j]] = box[ibox[j]] + w[j]
endfor
string = 'box = reform(box, '
for i = 0, ndim-2 do string = string + string(ngrid[i], ', ', format='(i0,a)')
string = string + string(ngrid[i], ')', format='(i0,a)')
checkthisval = execute(string)
end