tensorflow API: tf.one_hot
2018-01-06 13:29
393 查看
one_hot(indices, depth, on_value=None, off_value=None, axis=None, dtype=None, name=None)
参数:
indices: 需要进行独特编码的张量。
depth: 独热编码的长度。
on_value: 在独热处默认是编码为1(default: 1)
off_value: 默认使用0作为填充值(default: 0)
axis: 默认-1,表示最内部的轴进行。
dtype: 输出tensor的数据类型
例子:
参数:
indices: 需要进行独特编码的张量。
depth: 独热编码的长度。
on_value: 在独热处默认是编码为1(default: 1)
off_value: 默认使用0作为填充值(default: 0)
axis: 默认-1,表示最内部的轴进行。
dtype: 输出tensor的数据类型
例子:
```python indices = [0, 1, 2] depth = 3 tf.one_hot(indices, depth) # output: [3 x 3] # [[1., 0., 0.], # [0., 1., 0.], # [0., 0., 1.]]
indices = [0, 2, -1, 1] depth = 3 tf.one_hot(indices, depth, on_value=5.0, off_value=0.0, axis=-1) # output: [4 x 3] # [[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)
indices = [[0, 2], [1, -1]] depth = 3 tf.one_hot(indices, depth, on_value=1.0, off_value=0.0, axis=-1) # output: [2 x 2 x 3] # [[[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) ```
相关文章推荐
- tensorflow API:tf.split
- tensorflow API:tf.slice
- tensorflow API:tf.reduce_sum
- tensorflow API学习——tf.strided_slice
- tensorflow API:tf.not_equal
- tf-8.Tensorflow Object Dection API 物体检测
- tensorflow API:tf.truncated_normal
- tensorflow API:tf.argmin
- tensorflow API:tf.Variable
- tensorflow API: tf.unsorted_segment_sum
- tensorflow API: tf.unsorted_segment_sum
- tensorflow API:tf.control_dependencies
- tensorflow API: tf.clip_by_value
- tensorflow API:tf.group
- tensorflow API : tf.summary
- tensorflow API:tf.set_random_seed
- tensorflow API:tf.tile
- tensorflow API: tf.get_variable
- tensorflow API简单整理(二、变量共享)
- Tensorflow tf.nn.in_top_k Error targets[0] is out of range