阅读(2853) (9)

TensorFlow函数:tf.matrix_transpose

2017-11-01 18:26:44 更新

tf.matrix_transpose 函数
matrix_transpose(
    a,
    name='matrix_transpose'
)

定义在:tensorflow/python/ops/array_ops.py.

参考指南:数学函数>矩阵数学函数

转置张量 a 的最后两个维数.

例如:

# Matrix with no batch dimension.
# 'x' is [[1 2 3]
#         [4 5 6]]
tf.matrix_transpose(x) ==> [[1 4]
                                 [2 5]
                                 [3 6]]

# Matrix with two batch dimensions.
# x.shape is [1, 2, 3, 4]
# tf.matrix_transpose(x) is shape [1, 2, 4, 3]

注意,tf.matmul 提供 kwargs,它允许转置参数.这是以最小的成本完成的,并且比使用此函数更可取.例如:

# Good!  Transpose is taken at minimal additional cost.
tf.matmul(matrix, b, transpose_b=True)

# Inefficient!
tf.matmul(matrix, tf.matrix_transpose(b))

参数:

  • a:张量,并且 rank >= 2.
  • name:操作的名称(可选).

返回值:

该函数返回一个经过转置的批次矩阵张量.

可能引发的异常:

  • ValueError:如果 a 确定是静态的,并且 rank < 2.