parameters: (obs, guess, thresh=1e-5)
return_statement: return code_book, avg_dist[-1]
docstring: "raw" version of k-means.
  
      Returns
      -------
      code_book
          the lowest distortion codebook found.
      avg_dist
          the average distance a observation is from a code in the book.
          Lower means the code_book matches the data better.
  
      See Also
      --------
      kmeans : wrapper around k-means
  
      Examples
      --------
      Note: not whitened in this example.
  
      >>> from numpy import array
      >>> from scipy.cluster.vq import _kmeans
      >>> features  = array([[ 1.9,2.3],
      ...                    [ 1.5,2.5],
      ...                    [ 0.8,0.6],
      ...                    [ 0.4,1.8],
      ...                    [ 1.0,1.0]])
      >>> book = array((features[0],features[2]))
      >>> _kmeans(features,book)
      (array([[ 1.7       ,  2.4       ],
             [ 0.73333333,  1.13333333]]), 0.40563916697728591)
docstring_summary: "raw" version of k-means.
docstring_tokens: raw version of k - means .
function: def _kmeans(obs, guess, thresh=1e-5):
      """ "raw" version of k-means.
  
      Returns
      -------
      code_book
          the lowest distortion codebook found.
      avg_dist
          the average distance a observation is from a code in the book.
          Lower means the code_book matches the data better.
  
      See Also
      --------
      kmeans : wrapper around k-means
  
      Examples
      --------
      Note: not whitened in this example.
  
      >>> from numpy import array
      >>> from scipy.cluster.vq import _kmeans
      >>> features  = array([[ 1.9,2.3],
      ...                    [ 1.5,2.5],
      ...                    [ 0.8,0.6],
      ...                    [ 0.4,1.8],
      ...                    [ 1.0,1.0]])
      >>> book = array((features[0],features[2]))
      >>> _kmeans(features,book)
      (array([[ 1.7       ,  2.4       ],
             [ 0.73333333,  1.13333333]]), 0.40563916697728591)
  
      """
  
      code_book = array(guess, copy=True)
      avg_dist = []
      diff = thresh+1.
      while diff > thresh:
          nc = code_book.shape[0]
          # compute membership and distances between obs and code_book
          obs_code, distort = vq(obs, code_book)
          avg_dist.append(mean(distort, axis=-1))
          # recalc code_book as centroids of associated obs
          if(diff > thresh):
              code_book, has_members = _vq.update_cluster_means(obs, obs_code, nc)
              code_book = code_book.compress(has_members, axis=0)
          if len(avg_dist) > 1:
              diff = avg_dist[-2] - avg_dist[-1]
      # print avg_dist
      return code_book, avg_dist[-1]
function_tokens: def _kmeans ( obs , guess , thresh = 1e-5 ) : code_book = array ( guess , copy = True ) avg_dist = [ ] diff = thresh + 1. while diff > thresh : nc = code_book . shape [ 0 ] # compute membership and distances between obs and code_book obs_code , distort = vq ( obs , code_book ) avg_dist . append ( mean ( distort , axis = - 1 ) ) # recalc code_book as centroids of associated obs if ( diff > thresh ) : code_book , has_members = _vq . update_cluster_means ( obs , obs_code , nc ) code_book = code_book . compress ( has_members , axis = 0 ) if len ( avg_dist ) > 1 : diff = avg_dist [ - 2 ] - avg_dist [ - 1 ] # print avg_dist return code_book , avg_dist [ - 1 ]