codecamp

TensorFlow函数:tf.sparse_reshape

tf.sparse_reshape 函数

sparse_reshape(
    sp_input,
    shape,
    name=None
)

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

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

重塑一个 SparseTensor 以表示新密集形状中的值.

该操作在表示的稠密张量上与 reshape 具有相同的语义.sp_input 中非空值的索引是基于新的稠密形状被重新计算的,并且将返回包含新索引和新形状的新 SparseTensor.sp_input 中非空值的顺序不变.

如果 shape 中的一个分量是特殊值-1,则计算该维度的大小,以使总体密集大小保持不变.在 shape 中至多允许一个分量可以是-1.shape 中隐含的密集元素的数量必须与最初由 sp_input 表示的密集元素的数量相同.

例如,如果 sp_input 有形状 [2, 3, 6] 和 indices/values:

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

并且 shape 是 [9, -1],那么输出将是一个形状为 [9, 4] 并且有 indices/values 的 SparseTensor,如下所示:

[0, 0]: a
[0, 1]: b
[1, 2]: c
[4, 2]: d
[8, 1]: e

函数参数:

  • sp_input:输入的 SparseTensor.
  • shape:一个 1-D(矢量)int64 的 Tensor,指定所表示的 SparseTensor 的新密集形状.
  • name:返回张量的名称前缀(可选)

返回值:

具有相同非空值但具有由新致密形状计算的索引的 SparseTensor.

可能引发的异常:

  • TypeError:如果 sp_input 不是 SparseTensor.
  • ValueError:如果参数 shape 请求的 SparseTensor 的元素数量不同于 sp_input.
TensorFlow函数:tf.sparse_reset_shape
TensorFlow函数:tf.sparse_retain
温馨提示
下载编程狮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; }