tf.gather_nd 直观地做什么? [英] What does tf.gather_nd intuitively do?

查看:23
本文介绍了tf.gather_nd 直观地做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否直观地解释或给出更多关于 tf.gather_nd 在 Tensorflow 中索引和切片为高维张量的示例?

Can you intuitively explain or give more examples about tf.gather_nd for indexing and slicing into high-dimensional tensors in Tensorflow?

我阅读了 API,但我发现它非常简洁我自己很难理解函数的概念.

I read the API, but it is kept quite concise that I find myself hard to follow the function's concept.

推荐答案

好吧,这样想:

您提供了一个索引值列表来索引所提供的张量以获取这些切片.您提供的索引的第一个维度是您将执行的每个索引.让我们假设张量只是一个列表列表.

You are providing a list of index values to index the provided tensor to get those slices. The first dimension of the indices you provide is for each index you will perform. Let's pretend that tensor is just a list of lists.

[[0]] 表示您想在提供的张量中的索引 0 处获取一个特定的切片(列表).就像这样:

[[0]] means you want to get one specific slice(list) at index 0 in the provided tensor. Just like this:

[tensor[0]]

[[0], [1]] 表示您希望在索引 0 和 1 处获得两个特定切片,如下所示:

[[0], [1]] means you want get two specific slices at indices 0 and 1 like this:

[tensor[0], tensor[1]]

如果张量不止一维怎么办?我们做同样的事情:

Now what if tensor is more than one dimensions? We do the same thing:

[[0, 0]] 表示您想在第 0 个列表的索引 [0,0] 处获取一个切片.像这样:

[[0, 0]] means you want to get one slice at index [0,0] of the 0-th list. Like this:

[tensor[0][0]]

[[0, 1], [2, 3]] 表示您希望在提供的索引和维度处返回两个切片.像这样:

[[0, 1], [2, 3]] means you want return two slices at the indices and dimensions provided. Like this:

[tensor[0][1], tensor[2][3]]

我希望这是有道理的.我尝试使用 Python 索引来帮助解释在 Python 中如何对列表执行此操作.

I hope that makes sense. I tried using Python indexing to help explain how it would look in Python to do this to a list of lists.

这篇关于tf.gather_nd 直观地做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆