def _py_vq_1d(obs, code_book):
 raise RuntimeError('_py_vq_1d buggy, do not use rank 1 arrays for now')
 n = obs.size
 nc = code_book.size
 dist = np.zeros((n, nc))
 for i in range(nc):
  dist[:, i] = np.sum((obs - code_book[i]))
 print(dist)
 code = np.argmin(dist)
 min_dist = dist[code]
 return (code, np.sqrt(min_dist))

def _py_vq_1d ( obs , code_book ) : raise RuntimeError ( '_py_vq_1d buggy, do not use rank 1 arrays for now' ) n = obs . size nc = code_book . size dist = np . zeros ( ( n , nc ) ) for i in range ( nc ) : dist [ : , i ] = np . sum ( ( obs - code_book [ i ] ) ) print ( dist ) code = np . argmin ( dist ) min_dist = dist [ code ] return ( code , np . sqrt ( min_dist ) )
python version of vq algorithm for rank 1 only .