Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
flujo tensor:: operaciones:: uno caliente
#include <array_ops.h>
Devuelve un tensor one-hot.
Resumen
Las ubicaciones representadas por índices en indices
toman valor on_value
, mientras que todas las demás ubicaciones toman valor off_value
.
Si los indices
de entrada tienen rango N
, la salida tendrá rango N+1
. El nuevo eje se crea en axis
de dimensión (predeterminado: el nuevo eje se agrega al final).
Si indices
son escalares, la forma de salida será un vector de longitud depth
.
Si indices
son un vector de features
de longitud, la forma de salida será:
features x depth if axis == -1
depth x features if axis == 0
Si indices
es una matriz (lote) con forma [batch, features]
, la forma de salida será:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
Ejemplos
Supongamos que
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
Entonces la salida es [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)
Supongamos que
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
Entonces la salida es [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)
Supongamos que
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
Entonces la salida es [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)
]
Argumentos:
- alcance: un objeto de alcance
- índices: Un tensor de índices.
- profundidad: Un escalar que define la profundidad de una dimensión caliente.
- on_value: un escalar que define el valor para completar la salida cuando
indices[j] = i
. - off_value: un escalar que define el valor para completar la salida cuando
indices[j] != i
.
Atributos opcionales (ver Attrs
):
- eje: El eje a llenar (predeterminado: -1, un nuevo eje más interno).
Devoluciones:
Funciones estáticas públicas |
---|
Axis (int64 x) | |
Atributos públicos
Funciones públicas
nodo
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operador::tensorflow::Salida
operator::tensorflow::Output() const
Funciones estáticas públicas
Eje
Attrs Axis(
int64 x
)
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-26 (UTC).
[null,null,["Última actualización: 2025-07-26 (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\nArguments:\n\n- scope: A [Scope](/versions/r2.1/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.1/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.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value, const `[OneHot::Attrs](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_one_hot_1a120b99aec6bb831f0cec75b08bb8ab99) | `::`[tensorflow::Output](/versions/r2.1/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.1/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.1/api_docs/cc/struct/tensorflow/ops/one-hot/attrs) | Optional attribute setters for [OneHot](/versions/r2.1/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```"]]