W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
函數:tf.gather_nd
gather_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']]
參數:
返回值:
該函數返回一個張量.與參數具有相同的類型.參數值從索引所給定的索引中收集,并且具有形狀:indices.shape[:-1] + params.shape[indices.shape[-1]:]
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: