# OneHot

public final class **OneHot** Returns a one-hot tensor.


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)
       ]
     
<br />

<br />

<br />

<br />

<br />

<br />

### Nested Classes

|---|---|---|---|
| class | [OneHot.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot.Options) || Optional attributes for `https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot` |

### Public Methods

|---|---|
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot#asOutput())() Returns the symbolic handle of a tensor. |
| static [OneHot.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot.Options) | [axis](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot#axis(java.lang.Long))(Long axis) |
| static \<U, T extends Number\> [OneHot](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot)\<U\> | [create](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand<T>,%20org.tensorflow.Operand<java.lang.Integer>,%20org.tensorflow.Operand<U>,%20org.tensorflow.Operand<U>,%20org.tensorflow.op.core.OneHot.Options...))([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> indices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> depth, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> onValue, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> offValue, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot.Options) options) Factory method to create a class wrapping a new OneHot operation. |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [output](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot#output())() The one-hot tensor. |

### Inherited Methods

From class [org.tensorflow.op.PrimitiveOp](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp)

|---|---|
| final boolean | [equals](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |
| final int | [hashCode](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |
| [Operation](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation) | [op](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying `https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation` |
| final String | [toString](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface [org.tensorflow.Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)

|---|---|
| abstract [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |

## Public Methods

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\>
**asOutput**
()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.

<br />

#### public static [OneHot.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot.Options)
**axis**
(Long axis)

<br />

##### Parameters

| axis | The axis to fill (default: -1, a new inner-most axis). |
|---|---|

#### public static [OneHot](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot)\<U\>
**create**
([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> indices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> depth, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> onValue, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> offValue, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/OneHot.Options) options)

Factory method to create a class wrapping a new OneHot operation.

##### Parameters

| scope | current scope |
| indices | A tensor of indices. |
| depth | A scalar defining the depth of the one hot dimension. |
| onValue | A scalar defining the value to fill in output when \`indices\[j\] = i\`. |
| offValue | A scalar defining the value to fill in output when \`indices\[j\] != i\`. |
| options | carries optional attributes values |
|---|---|

##### Returns

- a new instance of OneHot

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\>
**output**
()

The one-hot tensor.