[Scipy-tickets] [SciPy] #546: scipy.cluster.vq.kmeans can throw IndexError

SciPy scipy-tickets@scipy....
Tue Nov 27 02:18:19 CST 2007


#546: scipy.cluster.vq.kmeans can throw IndexError
---------------------------+------------------------------------------------
 Reporter:  seiler         |       Owner:  somebody       
     Type:  defect         |      Status:  new            
 Priority:  normal         |   Milestone:  0.7            
Component:  scipy.cluster  |     Version:                 
 Severity:  major          |    Keywords:  cluster, kmeans
---------------------------+------------------------------------------------
 On line 321 of vq.py, {{{nc}}} is initialized to the number of rows in the
 array {{{code_book}}}.  At the end of the while loop immediately
 following, on line 337, some rows of {{{code_book}}} may be removed by a
 call to {{{take}}} if the corresponding clusters have no points in them.
 Since {{{nc}}} is set outside the while loop, when the while loop returns
 to the for loop at line 331 and loops through each row of {{{code_book}}},
 it loops up to the original value of {{{nc}}} past the end of the array,
 causing the exception to be thrown.

 This can be fixed by moving the definition of {{{nc}}} to inside the
 {{{while diff>thresh:}}} loop.

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/546>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list