codecamp

TensorFlow函数:tf.sparse_to_indicator

tf.sparse_to_indicator函数

sparse_to_indicator(
    sp_input,
    vocab_size,
    name=None
)

定义在:tensorflow/python/ops/sparse_ops.py.

请参阅指南:稀疏张量>转变

将 ids 的 SparseTensor 转换为稠密的布尔指示器张量.

sp_input.indices 的最后一个维度将被丢弃,并替换为 sp_input 的值.如果 sp_input.dense_shape = [D0, D1, ..., Dn, K],那么 output.shape = [D0, D1, ..., Dn, vocab_size],其中:

output[d_0, d_1, ..., d_n, sp_input[d_0, d_1, ..., d_n, k]] = True

在 output 的其他地方也是 False.

例如,如果 sp_input.dense_shape = [2, 3, 4] 使用非空值,则:

[0, 0, 0]: 0
[0, 1, 0]: 10
[1, 0, 3]: 103
[1, 1, 2]: 150
[1, 1, 3]: 149
[1, 1, 4]: 150
[1, 2, 1]: 121

并且 vocab_size = 200,那么输出将是一个 [2, 3, 200] 稠密的值为 False 的 bool 张量,它无处不在,除了以下的位置:

(0, 0, 0), (0, 1, 10), (1, 0, 103), (1, 1, 149), (1, 1, 150),
(1, 2, 121)

请注意,在输入 SparseTensor 中允许重复.此操作对于将 SparseTensors 转换为密集格式非常有用,以便与期望密集张量的操作符兼容.

输入 SparseTensor 必须按行优先顺序排列.

函数参数:

  • sp_input:具有 int32 或 int64 类型的 values 属性的 SparseTensor.
  • vocab_size:一个标量 Int64 的张量(或 Python INT),包含最后一个维度的新的大小,all(0 <= sp_input.values < vocab_size).
  • name:返回张量的名称前缀(可选).

函数返回值:

表示具有指定值的索引的稠密布尔指示器张量.

函数可能抛出的异常:

  • TypeError:如果 sp_input 不是 SparseTensor.
TensorFlow函数:tf.sparse_to_dense
TensorFlow函数:tf.sparse_transpose
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }