如何在TensorFlow中交换张量轴? [英] How do I swap tensor's axes in 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
),我在张量流中搜索了类似的内容,但没有发现任何东西.
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屋!