codecamp

TensorFlow函数:tf.sparse_retain

tf.sparse_retain 函数

sparse_retain(
    sp_input,
    to_retain
)

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

参见指南:稀疏张量>操纵

在一个 SparseTensor 中保留指定的非空值.

例如,如果 sp_input 有形状 [4, 5] 和4个非空字符串值,如下所示:

[0, 1]: a
[0, 3]: b
[2, 0]: c
[3, 1]: d

并且 to_retain = [True, False, False, True],则输出将是一个形状为 [4, 5] 以及具有2个非空值的 SparseTensor:

[0, 1]: a
[3, 1]: d

函数参数:

  • sp_input:输入的 SparseTensor 带有 N 个非空元素.
  • to_retain:长度为 N 的具有 M 个真值的 bool 向量.

函数返回值:

该函数返回一个与输入具有相同形状并且有 M 个非空元素的 SparseTensor,它对应于 to_retain 的真实位置.

可能引发的异常:

  • TypeError:如果 sp_input 不是 SparseTensor.
TensorFlow函数:tf.sparse_reshape
TensorFlow函数:tf.sparse_segment_mean
温馨提示
下载编程狮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; }