tf.transpose(
a,
perm=None,
name='transpose',
conjugate=False
)
作用:转置、共轭转置等。
参数
perm
: returned tensor’s dimension
i
will correspond to the input dimension
perm[i]
例子:
test = tf.random_normal([2,2,3],dtype=tf.float32)
with tf.Session() as sess:
#默认axis=0
#print(sess.run([test,tf.transpose(test)]),"\n")
print(sess.run([test,tf.transpose(test,perm=[1,2,0])]),"\n")
#print(sess.run([test,tf.transpose(test,perm=[1, 0, 2])]))
输出:
[array([[[ 0.8021455 , 0.505679 , 1.8120127 ],
[-0.03189123, 1.1534904 , 0.9760273 ]],
[[ 1.2107425 , -0.66847354, 0.73315024],
[ 1.304936 , 1.5720342 , 0.6012646 ]]], dtype=float32), array([[[ 0.8021455 , 1.2107425 ],
[ 0.505679 , -0.66847354],
[ 1.8120127 , 0.73315024]],
[[-0.03189123, 1.304936 ],
[ 1.1534904 , 1.5720342 ],
[ 0.9760273 , 0.6012646 ]]], dtype=float32)]
相当于对矩阵为元素的numpy array做
转置
。
二维的情况:
x = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.transpose(x) # [[1, 4]
# [2, 5]
# [3, 6]]
# Equivalently
tf.transpose(x, perm=[1, 0]) # [[1, 4]
# [2, 5]
# [3, 6]]
版权声明:本文为NockinOnHeavensDoor原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。