; docformat = 'rst' ;+ ; This shows the IDL help is wrong when it says:: ; ; For example, make the histogram of array A: ; H = HISTOGRAM(A, REVERSE_INDICES = R) ; ; ;Set all elements of A that are in the ith bin of H to 0. ; IF R[i] NE R[i+1] THEN A[R[R[I] : R[i+1]-1]] = 0 ; The above is usually more efficient than the following: ; bini = WHERE(A EQ i, count) ; IF count NE 0 THEN A[bini] = 0 ;- n = 100000 i = 45 ntimings = 100 histogramTimes = fltarr(ntimings) whereTimes = fltarr(ntimings) for j = 0L, ntimings - 1L do begin d = fix(100 * randomu(seed, n)) t0 = systime(/seconds) d1 = d h = histogram(d1, reverse_indices=r) if (r[i] lt r[i+1]) then d1[r[r[i]:r[i+1]-1]] = 0 t1 = systime(/seconds) histogramTimes[j] = t1 - t0 t0 = systime(/seconds) d2 = d ind = where(d2 eq i, count) if (count gt 0L) then d2[ind] = 0 t1 = systime(/seconds) whereTimes[j] = t1 - t0 endfor print, total(histogramTimes) / ntimings, format='(%"Average time for HISTOGRAM: %f")' print, total(whereTimes) / ntimings, format='(%"Average time for WHERE: %f")' end