def dense_to_one_hot(labels, n_classes=2):
 labels = np.array(labels)
 n_labels = labels.shape[0]
 index_offset = (np.arange(n_labels) * n_classes)
 labels_one_hot = np.zeros((n_labels, n_classes), dtype=np.float32)
 labels_one_hot.flat[(index_offset + labels.ravel())] = 1
 return labels_one_hot

def dense_to_one_hot ( labels , n_classes = 2 ) : labels = np . array ( labels ) n_labels = labels . shape [ 0 ] index_offset = ( np . arange ( n_labels ) * n_classes ) labels_one_hot = np . zeros ( ( n_labels , n_classes ) , dtype = np . float32 ) labels_one_hot . flat [ ( index_offset + labels . ravel ( ) ) ] = 1 return labels_one_hot
convert class labels from scalars to one-hot vectors .