MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / transpose_v2

Function transpose_v2

tensorflow/python/ops/array_ops.py:1702–1768  ·  view source on GitHub ↗

Transposes `a`. Permutes the dimensions according to `perm`. The returned tensor's dimension i will correspond to the input dimension `perm[i]`. If `perm` is not given, it is set to (n-1...0), where n is the rank of the input tensor. Hence by default, this operation performs a regular ma

(a, perm=None, conjugate=False, name="transpose")

Source from the content-addressed store, hash-verified

1700
1701@tf_export("transpose", v1=[])
1702def transpose_v2(a, perm=None, conjugate=False, name="transpose"):
1703 """Transposes `a`.
1704
1705 Permutes the dimensions according to `perm`.
1706
1707 The returned tensor's dimension i will correspond to the input dimension
1708 `perm[i]`. If `perm` is not given, it is set to (n-1...0), where n is
1709 the rank of the input tensor. Hence by default, this operation performs a
1710 regular matrix transpose on 2-D input Tensors. If conjugate is True and
1711 `a.dtype` is either `complex64` or `complex128` then the values of `a`
1712 are conjugated and transposed.
1713
1714 @compatibility(numpy)
1715 In `numpy` transposes are memory-efficient constant time operations as they
1716 simply return a new view of the same data with adjusted `strides`.
1717
1718 TensorFlow does not support strides, so `transpose` returns a new tensor with
1719 the items permuted.
1720 @end_compatibility
1721
1722 For example:
1723
1724 ```python
1725 x = tf.constant([[1, 2, 3], [4, 5, 6]])
1726 tf.transpose(x) # [[1, 4]
1727 # [2, 5]
1728 # [3, 6]]
1729
1730 # Equivalently
1731 tf.transpose(x, perm=[1, 0]) # [[1, 4]
1732 # [2, 5]
1733 # [3, 6]]
1734
1735 # If x is complex, setting conjugate=True gives the conjugate transpose
1736 x = tf.constant([[1 + 1j, 2 + 2j, 3 + 3j],
1737 [4 + 4j, 5 + 5j, 6 + 6j]])
1738 tf.transpose(x, conjugate=True) # [[1 - 1j, 4 - 4j],
1739 # [2 - 2j, 5 - 5j],
1740 # [3 - 3j, 6 - 6j]]
1741
1742 # 'perm' is more useful for n-dimensional tensors, for n > 2
1743 x = tf.constant([[[ 1, 2, 3],
1744 [ 4, 5, 6]],
1745 [[ 7, 8, 9],
1746 [10, 11, 12]]])
1747
1748 # Take the transpose of the matrices in dimension-0
1749 # (this common operation has a shorthand `linalg.matrix_transpose`)
1750 tf.transpose(x, perm=[0, 2, 1]) # [[[1, 4],
1751 # [2, 5],
1752 # [3, 6]],
1753 # [[7, 10],
1754 # [8, 11],
1755 # [9, 12]]]
1756 ```
1757
1758 Args:
1759 a: A `Tensor`.

Callers

nothing calls this directly

Calls 1

transposeFunction · 0.70

Tested by

no test coverage detected