c语言gather函数,TensorFlow函数:tf.gather_nd
函數:tf.gather_ndgather_nd(
params,
indices,
name=None
)
將參數中的切片收集到由索引指定的形狀的張量中.
索引(indices)是一個 k 維整數張量,最好作為一個 (k-1) 維的索引(indices)張量的參數,其中每個元素定義了一個參數切片:output[i_0, ..., i_{K-2}] = params[indices[i0, ..., i_{K-2}]]
然而在 tf.gather 函數中,將片段定義為參數的第一維度;在 tf.gather_nd 中,索引將切片定義為參數的第一個 n 維度.其中: N?=?indices.shape[-1]
索引的最后一個維度最多可以是參數的秩:indices.shape[-1] <= params.rank
索引的最后一個維度對應于元素?(如果 indices.shape[-1] == params.rank) 或切片 (如果 indices.shape[-1] < params.rank) 沿參數 dices.shape[-1] 中的維度.輸出張量具有形狀:indices.shape[:-1] + params.shape[indices.shape[-1]:]
下面是一些例子:
簡單的索引到矩陣:indices = [[0, 0], [1, 1]]
params = [['a', 'b'], ['c', 'd']]
output = ['a', 'd']
將索引分為矩陣:indices = [[1], [0]]
params = [['a', 'b'], ['c', 'd']]
output = [['c', 'd'], ['a', 'b']]
索引到一個3-tensor:indices = [[1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['a1', 'b1'], ['c1', 'd1']]]
indices = [[0, 1], [1, 0]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['c0', 'd0'], ['a1', 'b1']]
indices = [[0, 0, 1], [1, 0, 1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = ['b0', 'b1']
分批索引到矩陣中:indices = [[[0, 0]], [[0, 1]]]
params = [['a', 'b'], ['c', 'd']]
output = [['a'], ['b']]
分批切片索引成矩陣:indices = [[[1]], [[0]]]
params = [['a', 'b'], ['c', 'd']]
output = [[['c', 'd']], [['a', 'b']]]
分批索引到一個 3-tensor:indices = [[[1]], [[0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[[['a1', 'b1'], ['c1', 'd1']]],
[[['a0', 'b0'], ['c0', 'd0']]]]
indices = [[[0, 1], [1, 0]], [[0, 0], [1, 1]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['c0', 'd0'], ['a1', 'b1']],
[['a0', 'b0'], ['c1', 'd1']]]
indices = [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['b0', 'b1'], ['d0', 'c1']]
參數:
params:張量.這個張量是用來收集數值的.
indices:張量.必須是以下類型之一:int32,int64;索引張量.
name:操作的名稱(可選).
返回值:
該函數返回一個張量.與參數具有相同的類型.參數值從索引所給定的索引中收集,并且具有形狀:indices.shape[:-1] + params.shape[indices.shape[-1]:]
總結
以上是生活随笔為你收集整理的c语言gather函数,TensorFlow函数:tf.gather_nd的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个向钱看向厚赚个性签名
- 下一篇: 谷歌不更新android studio,