tensorflow - 如何从索引值中获取值

标签 tensorflow

张量是A_tensor,形状为[3,3,3],我想通过索引获取最后一个轴的值​​。

如何在 Tensorflow 中做到这一点?

A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])

如何获取张量([[1,2],[2,3],[3,4]])

最佳答案

您可以使用tf.gather():

A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])
tf.gather(A_tensor,[[0,1]],axis=-1)

关于tensorflow - 如何从索引值中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65622728/

相关文章:

python - 检查输入 : expected flatten_input to have 3 dimensions, 但获得形状为 (None, 100, 100, 1) 的数组时出错

python - 在 Keras 自定义层中获取批量大小并使用 tensorflow 操作(tf.Variable)

machine-learning - 为什么梯度下降会更新 0 值权重?

Tensorflow:如何使用自定义常量滤波器对图像进行卷积

tensorflow - 我的测试图像也需要预处理吗?

tensorflow - Keras 无法计算 Keras 自定义层中的参数数量

machine-learning - Tensorflow - 图形是如何执行的?

python - 如何在 Azure ML 中使用 TensorFlow Hub

swift - Amazon EC2 T2 实例是否适合运行 TensorFlow Mobile 或 TensorFlow Lite?

machine-learning - Keras 预训练的 Xception 模型总是给出预测 'sewing_machine'