Created
January 29, 2019 03:20
-
-
Save upidea/339bb373f2ad217f29f039cb13bfa539 to your computer and use it in GitHub Desktop.
numpy的one_hot编码函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = numpy.arange(num_labels) * num_classes | |
| labels_one_hot = numpy.zeros((num_labels, num_classes)) | |
| labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1 | |
| return labels_one_hot | |
| 看起来 这是一段代码 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment