當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python mxnet.ndarray.gather_nd用法及代碼示例

用法:

mxnet.ndarray.gather_nd(data=None, indices=None, out=None, name=None, **kwargs)

參數

  • data(NDArray) - 數據
  • indices(NDArray) - index
  • out(NDArray, optional) - 輸出 NDArray 來保存結果。

返回

out- 此函數的輸出。

返回類型

NDArray 或 NDArray 列表

data 收集元素或切片並存儲到形狀由 indices 定義的張量。

給定形狀為 data(X_0, X_1, …, X_{N-1}) 和形狀為 (M, Y_0, …, Y_{K-1}) 的索引,輸出將具有形狀 (Y_0, …, Y_{K-1}, X_M, …, X_{N-1}) ,其中 M <= N 。如果 M == N ,輸出形狀將隻是 (Y_0, …, Y_{K-1})

輸出中的元素定義如下:

output[y_0, ..., y_{K-1}, x_M, ..., x_{N-1}] = data[indices[0, y_0, ..., y_{K-1}],
                                                    ...,
                                                    indices[M-1, y_0, ..., y_{K-1}],
                                                    x_M, ..., x_{N-1}]

例子:

data = [[0, 1], [2, 3]]
indices = [[1, 1, 0], [0, 1, 0]]
gather_nd(data, indices) = [2, 3, 0]

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
indices = [[0, 1], [1, 0]]
gather_nd(data, indices) = [[3, 4], [5, 6]]

相關用法


注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.ndarray.gather_nd。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。