Convert indices to one-hot encoding. Args: indices: A list of `int` indices with length `n`, each eleemnt of which is assumed to be a zero-based class index >= 0 and < `num_classes`. num_classes: Total number of possible classes as an `int`. Returns: A numpy ndarray of shape
(indices, num_classes)
| 202 | |
| 203 | |
| 204 | def _to_one_hot(indices, num_classes): |
| 205 | """Convert indices to one-hot encoding. |
| 206 | |
| 207 | Args: |
| 208 | indices: A list of `int` indices with length `n`, each eleemnt of which is |
| 209 | assumed to be a zero-based class index >= 0 and < `num_classes`. |
| 210 | num_classes: Total number of possible classes as an `int`. |
| 211 | |
| 212 | Returns: |
| 213 | A numpy ndarray of shape [n, num_classes] and dtype `float32`. |
| 214 | """ |
| 215 | one_hot = np.zeros([len(indices), num_classes], dtype=np.float32) |
| 216 | one_hot[np.arange(len(indices)), indices] = 1 |
| 217 | return one_hot |