def compressed_one_hot(labels, dtype=None, out=None, simplify_binary=True, mode='stack', sparse=False):
 labels = _validate_labels(labels, ndim=1)
 labels_ = labels.copy()
 uniq = np.unique(labels_)
 for (i, e) in enumerate(uniq):
  labels_[(labels_ == e)] = i
 if (simplify_binary and (len(uniq) == 2)):
  return (labels_.reshape((labels_.shape[0], 1)), uniq)
 else:
  return (OneHotFormatter(len(uniq), dtype=dtype).format(labels_, mode=mode, sparse=sparse), uniq)

def compressed_one_hot ( labels , dtype = None , out = None , simplify_binary = True , mode = 'stack' , sparse = False ) : labels = _validate_labels ( labels , ndim = 1 ) labels_ = labels . copy ( ) uniq = np . unique ( labels_ ) for ( i , e ) in enumerate ( uniq ) : labels_ [ ( labels_ == e ) ] = i if ( simplify_binary and ( len ( uniq ) == 2 ) ) : return ( labels_ . reshape ( ( labels_ . shape [ 0 ] , 1 ) ) , uniq ) else : return ( OneHotFormatter ( len ( uniq ) , dtype = dtype ) . format ( labels_ , mode = mode , sparse = sparse ) , uniq )
construct a one-hot matrix from a vector of integer labels .