The locations represented by indices in indices take value on_value,
while all other locations take value off_value.
on_value and off_value must have matching data types. If dtype is also
provided, they must be the same data type as specified by dtype.
If on_value is not provided, it will default to the value 1 with type
dtype
If off_value is not provided, it will default to the value 0 with type
dtype
If the input indices is rank N, the output will have rank N+1. The
new axis is created at dimension axis (default: the new axis is appended
at the end).
If indices is a scalar the output shape will be a vector of length depth
If indices is a vector of length features, the output shape will be:
featuresxdepthifaxis==-1depthxfeaturesifaxis==0
If indices is a matrix (batch) with shape [batch, features], the output
shape will be:
If dtype is not provided, it will attempt to assume the data type of
on_value or off_value, if one or both are passed in. If none of
on_value, off_value, or dtype are provided, dtype will default to the
value tf.float32.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.one_hot\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/one_hot) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/array_ops.py#L3371-L3514) |\n\nReturns a one-hot tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.one_hot`](/api_docs/python/tf/one_hot)\n\n\u003cbr /\u003e\n\n tf.one_hot(\n indices, depth, on_value=None, off_value=None, axis=None, dtype=None, name=None\n )\n\nThe locations represented by indices in `indices` take value `on_value`,\nwhile all other locations take value `off_value`.\n\n`on_value` and `off_value` must have matching data types. If `dtype` is also\nprovided, they must be the same data type as specified by `dtype`.\n\nIf `on_value` is not provided, it will default to the value `1` with type\n`dtype`\n\nIf `off_value` is not provided, it will default to the value `0` with type\n`dtype`\n\nIf the input `indices` is rank `N`, the output will have rank `N+1`. The\nnew axis is created at dimension `axis` (default: the new axis is appended\nat the end).\n\nIf `indices` is a scalar the output shape will be a vector of length `depth`\n\nIf `indices` is a vector of length `features`, the output shape will be: \n\n features x depth if axis == -1\n depth x features if axis == 0\n\nIf `indices` is a matrix (batch) with shape `[batch, features]`, the output\nshape will be: \n\n batch x features x depth if axis == -1\n batch x depth x features if axis == 1\n depth x batch x features if axis == 0\n\nIf `dtype` is not provided, it will attempt to assume the data type of\n`on_value` or `off_value`, if one or both are passed in. If none of\n`on_value`, `off_value`, or `dtype` are provided, `dtype` will default to the\nvalue [`tf.float32`](../tf#float32).\n| **Note:** If a non-numeric data type output is desired ([`tf.string`](../tf#string), [`tf.bool`](../tf#bool), etc.), both `on_value` and `off_value` *must* be provided to `one_hot`.\n\n#### For example:\n\n indices = [0, 1, 2]\n depth = 3\n tf.one_hot(indices, depth) # output: [3 x 3]\n # [[1., 0., 0.],\n # [0., 1., 0.],\n # [0., 0., 1.]]\n\n indices = [0, 2, -1, 1]\n depth = 3\n tf.one_hot(indices, depth,\n on_value=5.0, off_value=0.0,\n axis=-1) # output: [4 x 3]\n # [[5.0, 0.0, 0.0], # one_hot(0)\n # [0.0, 0.0, 5.0], # one_hot(2)\n # [0.0, 0.0, 0.0], # one_hot(-1)\n # [0.0, 5.0, 0.0]] # one_hot(1)\n\n indices = [[0, 2], [1, -1]]\n depth = 3\n tf.one_hot(indices, depth,\n on_value=1.0, off_value=0.0,\n axis=-1) # output: [2 x 2 x 3]\n # [[[1.0, 0.0, 0.0], # one_hot(0)\n # [0.0, 0.0, 1.0]], # one_hot(2)\n # [[0.0, 1.0, 0.0], # one_hot(1)\n # [0.0, 0.0, 0.0]]] # one_hot(-1)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------|\n| `indices` | A `Tensor` of indices. |\n| `depth` | A scalar defining the depth of the one hot dimension. |\n| `on_value` | A scalar defining the value to fill in output when `indices[j] = i`. (default: 1) |\n| `off_value` | A scalar defining the value to fill in output when `indices[j] != i`. (default: 0) |\n| `axis` | The axis to fill (default: -1, a new inner-most axis). |\n| `dtype` | The data type of the output tensor. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|----------|---------------------|\n| `output` | The one-hot tensor. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|------------------------------------------------------------------|\n| `TypeError` | If dtype of either `on_value` or `off_value` don't match `dtype` |\n| `TypeError` | If dtype of `on_value` and `off_value` don't match one another |\n\n\u003cbr /\u003e"]]