def recreate_image(codebook, labels, w, h):
 d = codebook.shape[1]
 image = np.zeros((w, h, d))
 label_idx = 0
 for i in range(w):
  for j in range(h):
   image[i][j] = codebook[labels[label_idx]]
   label_idx += 1
 return image

def recreate_image ( codebook , labels , w , h ) : d = codebook . shape [ 1 ] image = np . zeros ( ( w , h , d ) ) label_idx = 0 for i in range ( w ) : for j in range ( h ) : image [ i ] [ j ] = codebook [ labels [ label_idx ] ] label_idx += 1 return image
recreate the image from the code book & labels .