Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::OneHot
#include <array_ops.h>
Returns a one-hot tensor.
Summary
The locations represented by indices in indices
take value on_value
, while all other locations take value off_value
.
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:
features x depth if axis == -1
depth x features if axis == 0
If indices
is a matrix (batch) with shape [batch, features]
, the output shape will be:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
Examples
Suppose that
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
Then output is [4 x 3]
:
output =
[5.0 0.0 0.0] // one_hot(0)
[0.0 0.0 5.0] // one_hot(2)
[0.0 0.0 0.0] // one_hot(-1)
[0.0 5.0 0.0] // one_hot(1)
Suppose that
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
Then output is [3 x 4]
:
output =
[0.0 3.0 3.0 3.0]
[3.0 3.0 3.0 0.0]
[3.0 3.0 3.0 3.0]
[3.0 0.0 3.0 3.0]
// ^ one_hot(0)
// ^ one_hot(2)
// ^ one_hot(-1)
// ^ one_hot(1)
Suppose that
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
Then output is [2 x 2 x 3]
:
output =
[
[1.0, 0.0, 0.0] // one_hot(0)
[0.0, 0.0, 1.0] // one_hot(2)
][
[0.0, 1.0, 0.0] // one_hot(1)
[0.0, 0.0, 0.0] // one_hot(-1)
]
Args:
- scope: A Scope object
- indices: A tensor of indices.
- depth: A scalar defining the depth of the one hot dimension.
- on_value: A scalar defining the value to fill in output when
indices[j] = i
.
- off_value: A scalar defining the value to fill in output when
indices[j] != i
.
Optional attributes (see Attrs
):
- axis: The axis to fill (default: -1, a new inner-most axis).
Returns:
Public static functions
|
Axis(int64 x)
|
|
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Public static functions
Axis
Attrs Axis(
int64 x
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tensorflow::ops::OneHot Class Reference\n\ntensorflow::ops::OneHot\n=======================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns a one-hot tensor.\n\nSummary\n-------\n\nThe locations represented by indices in `indices` take value `on_value`, while all other locations take value `off_value`.\n\nIf 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).\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```text\n features x depth if axis == -1\n depth x features if axis == 0\n```\n\n\u003cbr /\u003e\n\nIf `indices` is a matrix (batch) with shape `[batch, features]`, the output shape will be: \n\n```text\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```\n\n\u003cbr /\u003e\n\n\nExamples\n========\n\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [0, 2, -1, 1]\n depth = 3\n on_value = 5.0\n off_value = 0.0\n axis = -1\n```\n\n\u003cbr /\u003e\n\nThen output is `[4 x 3]`: \n\n```scdoc\noutput =\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\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [0, 2, -1, 1]\n depth = 3\n on_value = 0.0\n off_value = 3.0\n axis = 0\n```\n\n\u003cbr /\u003e\n\nThen output is `[3 x 4]`: \n\n```scdoc\noutput =\n [0.0 3.0 3.0 3.0]\n [3.0 3.0 3.0 0.0]\n [3.0 3.0 3.0 3.0]\n [3.0 0.0 3.0 3.0]\n// ^ one_hot(0)\n// ^ one_hot(2)\n// ^ one_hot(-1)\n// ^ one_hot(1)\n```\n\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [[0, 2], [1, -1]]\n depth = 3\n on_value = 1.0\n off_value = 0.0\n axis = -1\n```\n\n\u003cbr /\u003e\n\nThen output is `[2 x 2 x 3]`: \n\n```scdoc\noutput =\n [\n [1.0, 0.0, 0.0] // one_hot(0)\n [0.0, 0.0, 1.0] // one_hot(2)\n ][\n [0.0, 1.0, 0.0] // one_hot(1)\n [0.0, 0.0, 0.0] // one_hot(-1)\n ]\n```\n\n\u003cbr /\u003e\n\nArgs:\n\n- scope: A [Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\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`.\n- off_value: A scalar defining the value to fill in output when `indices[j] != i`.\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs)):\n\n- axis: The axis to fill (default: -1, a new inner-most axis).\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The one-hot tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [OneHot](#classtensorflow_1_1ops_1_1_one_hot_1a854f72c62e64f05c6b259c56ea5734bf)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value)` ||\n| [OneHot](#classtensorflow_1_1ops_1_1_one_hot_1a606bee0fc38c4a1041cb1cd0be5920ca)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value, const `[OneHot::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_one_hot_1aa5fc51f1f352f7ce7ffb0906b98ab4ec) | [Operation](/versions/r2.14/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_one_hot_1a120b99aec6bb831f0cec75b08bb8ab99) | `::`[tensorflow::Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_one_hot_1a79ee3b14e2833cd20e87ac9ed19c8852)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_one_hot_1afd6cf127f64b799170e3bbdb63bbf3a8)`() const ` | |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_one_hot_1aeb4ae438117dbe3d0e9a0ff8af670b54)`() const ` | |\n\n| ### Public static functions ||\n|-------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|\n| [Axis](#classtensorflow_1_1ops_1_1_one_hot_1a11c56717df9255c7d78ae73a2a9349f6)`(int64 x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs) |\n\n| ### Structs ||\n|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::OneHot::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/one-hot/attrs) | Optional attribute setters for [OneHot](/versions/r2.14/api_docs/cc/class/tensorflow/ops/one-hot#classtensorflow_1_1ops_1_1_one_hot). |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### OneHot\n\n```gdscript\n OneHot(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input indices,\n ::tensorflow::Input depth,\n ::tensorflow::Input on_value,\n ::tensorflow::Input off_value\n)\n``` \n\n### OneHot\n\n```gdscript\n OneHot(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input indices,\n ::tensorflow::Input depth,\n ::tensorflow::Input on_value,\n ::tensorflow::Input off_value,\n const OneHot::Attrs & attrs\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n``` \n\nPublic static functions\n-----------------------\n\n### Axis\n\n```text\nAttrs Axis(\n int64 x\n)\n```"]]