gpt4 book ai didi

tensorflow - 如何在 TensorFlow 中选择二维张量的某些列?

转载 作者:行者123 更新时间:2023-12-03 15:22:30 28 4
gpt4 key购买 nike

由于正在 this issue 中进行广义切片,实现 2D 张量(矩阵)的 op 收集列的最佳方法是什么?例如,对于张量 t :

1 2 3 4
5 6 7 8

和指数 [1,3],我想得到:
2 4
6 8

相当于 numpy t[:, [1,3]] .

最佳答案

同时gather方法有一个 axis范围。

import tensorflow as tf
params = tf.constant([[1,2,3],[4,5,6]])
indices = [0,2]
op = tf.gather(params, indices, axis=1)

产生输出
[[1 3]
[4 6]]

关于tensorflow - 如何在 TensorFlow 中选择二维张量的某些列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37670886/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com