codecamp

TensorFlow张量变换函数:tf.gather

函数:tf.gather
gather(
    params,
    indices,
    validate_indices=None,
    name=None,
    axis=0
)

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

参见指南:张量变换>切片和连接

根据索引从参数轴上收集切片.
索引必须是任何维度的整数张量 (通常为 0-D 或 1-D).生成输出张量该张量的形状为:params.shape[:axis] + indices.shape + params.shape[axis + 1:]

使用示例如下:

# Scalar indices (output is rank(params) - 1).
output[a_0, ..., a_n, b_0, ..., b_n] =
  params[a_0, ..., a_n, indices, b_0, ..., b_n]

# Vector indices (output is rank(params)).
output[a_0, ..., a_n, i, b_0, ..., b_n] =
  params[a_0, ..., a_n, indices[i], b_0, ..., b_n]

# Higher rank indices (output is rank(params) + rank(indices) - 1).
output[a_0, ..., a_n, i, ..., j, b_0, ... b_n] =
  params[a_0, ..., a_n, indices[i, ..., j], b_0, ..., b_n]

TensorFlow张量变换函数:tf.gather

参数:

  • params:一个张量.这个张量是用来收集数值的.该张量的秩必须至少是 axis + 1.
  • indices:一个张量.必须是以下类型之一:int32,int64.索引张量必须在 [0, params.shape[axis]) 范围内.
  • axis:一个张量.必须是以下类型之一:int32,int64.在参数轴从中收集索引.默认为第一个维度.支持负索引.
  • name:操作的名称(可选).

返回值:

该函数返回一个张量.与参数具有相同的类型.参数值从索引给定的索引中收集而来,并且形状为:params.shape[:axis] + indices.shape + params.shape[axis + 1:].

TensorFlow高阶函数:tf.foldl
TensorFlow函数:tf.gather_nd
温馨提示
下载编程狮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; }