如何在 TensorFlow 中交换张量的轴? [英] How do I swap tensor's axes in TensorFlow?

查看:43
本文介绍了如何在 TensorFlow 中交换张量的轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形状为 (30, 116, 10) 的张量,我想交换前两个维度,以便我有一个形状为 (116, 30,10)

I have a tensor of shape (30, 116, 10), and I want to swap the first two dimensions, so that I have a tensor of shape (116, 30, 10)

我看到 numpy 作为这样一个实现的函数 (np.swapaxes),我在 tensorflow 中搜索了类似的东西,但我什么也没找到.

I saw that numpy as such a function implemented (np.swapaxes) and I searched for something similar in tensorflow but I found nothing.

你有什么想法吗?

推荐答案

tf.transpose 提供与 np.swapaxes 相同的功能,但形式更通用.在您的情况下,您可以执行 tf.transpose(orig_tensor, [1, 0, 2]) 这相当于 np.swapaxes(orig_np_array, 0, 1).

tf.transpose provides the same functionality as np.swapaxes, although in a more generalized form. In your case, you can do tf.transpose(orig_tensor, [1, 0, 2]) which would be equivalent to np.swapaxes(orig_np_array, 0, 1).

这篇关于如何在 TensorFlow 中交换张量的轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆