How to speed up code which checks lots of values of an array [message #74367] |
Thu, 13 January 2011 08:06  |
Robin Wilson
Messages: 40 Registered: August 2010
|
Member |
|
|
Hi all,
I've been writing some code which checks that all of the values in one
half of an array are less than a threshold, and all of the values on the
right half of an array are greater than a threshold. I've written the
code below, which seems to be a fairly clean way of writing it, and
works for any length of array (which is important for my use of it).
However, it's not very fast. I wondered if it might be able to be sped
up using some sort of magic like the Histogram command... Any ideas?
---CODE---
; Assume we're given a 1D array called line with our values in it
len = N_ELEMENTS(line)
section_len = (len - 1) / 2
; Get the left-hand half of the array
LHS = line[0:section_len - 1]
RHS = line[section_len + 1: len - 1]
res = WHERE(LHS GT 180, LHS_count)
res = WHERE(RHS LT 180, RHS_count)
IF LHS_count EQ 0 AND RHS_count EQ 0 THEN BEGIN
; Do stuff
ENDIF
---END CODE---
Cheers,
Robin
|
|
|
|