Merge pull request #34829 from rpalakkal:usage-example

PiperOrigin-RevId: 304022323
Change-Id: Ib0b7ab3f9d1ae752010995eca2d3214ad94a991e
This commit is contained in:
TensorFlower Gardener 2020-03-31 12:40:52 -07:00
commit a65548896c

View File

@ -61,6 +61,22 @@ def to_categorical(y, num_classes=None, dtype='float32'):
Returns:
A binary matrix representation of the input. The classes axis is placed
last.
Usage example:
>>> y = [0, 1, 2, 3, 3, 1, 0]
>>> tf.keras.utils.to_categorical(y, 4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.],
[0., 0., 0., 1.],
[0., 1., 0., 0.],
[1., 0., 0., 0.]], dtype=float32)
Raises:
Value Error: If input contains string value
"""
y = np.array(y, dtype='int')
input_shape = y.shape