MCPcopy
hub / github.com/tensorflow/tfjs-examples / _to_one_hot

Function _to_one_hot

iris/python/iris_data.py:204–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

202
203
204def _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

Callers 1

loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected