(labels_dense, num_classes)
return labels_one_hot
Convert class labels from scalars to one-hot vectors.
Convert class labels from scalars to one-hot vectors.
Convert class labels from scalars to one - hot vectors .
def dense_to_one_hot(labels_dense, num_classes):
  """Convert class labels from scalars to one-hot vectors."""
  num_labels = labels_dense.shape[0]
  index_offset = np.arange(num_labels) * num_classes
  labels_one_hot = np.zeros((num_labels, num_classes))
  labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1  # pylint:disable=unsupported-assignment-operation
  return labels_one_hot
def dense_to_one_hot ( labels_dense , num_classes ) : num_labels = labels_dense . shape [ 0 ] index_offset = np . arange ( num_labels ) * num_classes labels_one_hot = np . zeros ( ( num_labels , num_classes ) ) labels_one_hot . flat [ index_offset + labels_dense . ravel ( ) ] = 1 # pylint:disable=unsupported-assignment-operation return labels_one_hot