comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: slow processing of my k-nearest neighour code
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: slow processing of my k-nearest neighour code [message #49786 is a reply to message #49785] Mon, 14 August 2006 07:11 Go to previous messageGo to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
humphreymurray@gmail.com wrote:

>> ; Calculate the squared distance for each attribute.
>> squared = make_array(num_training_elements, num_attributes)
>> for attrib = 0, num_attributes-1 do begin
>> squared[*,attrib] = (testing_data[i, attrib] -
>> training_data[*,attrib])^2
>> endfor
>>

Hi,

You might try replacing the above for inner-loop with the following

squared = (testing_data - training_data)^2

Since IDL is array saavy it will perform the operation element by
element for you quite quickly (as well as make the "squared" array for you).

You might be able to eliminate the outer-loop, too, but I am less sure
of that. Take a peek at the for-loop bible at

http://www.dfanning.com/tips/forloops.html

Good luck,
Ben
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Help with GRID_TPS
Next Topic: Re: SHMMAP and structures

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:04:44 PDT 2025

Total time taken to generate the page: 0.88230 seconds