X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 27 Jul 2012 01:12 AM by  anon
Fastest way to find value in sorted list?
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
27 Jul 2012 01:12 AM
    Hi Guys, I'm wondering if someone can help me speed up my code. I'm basically looping through a large array and comparing values with two other large sorted arrays trying to find the value thats equal to or less than that value. I'm currently using a where procedure but I'm sure there has to be a faster way to search as I'm not looking for multiple values as the where finds, I'm just after one value. Anyway here is an example of my code: For k = 0L, numDataElements-1 do begin data_lon = data[k].point_x data_lat = data[k].point_y ; find the indices from the lat-lon arrays idx1 = where(lon LE data_lon, count1) idx2 = where(lat LE data_lat, count2) If (count1 GT 0) && (count2 GT 0) then begin idx1 = idx1[count1-1] idx2 = idx2[count2-1] ; do stuff here endif endfor Thanks, Tim

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Jul 2012 07:19 PM
    Ok I managed to speed this up using a binary search but then I realised this was not were the code was being slowed down. It due to the IDL restore procedure being so sloooooow. I will start a new thread about this issue but just for reference I compared the IDL restore with the readsav function from Pythons scipy library and the Python library was 3x faster. Why is IDL so slow at restoring its own files???
    You are not authorized to post a reply.