Transpose - version 13#

This page documents version 13 of operator Transpose. See Transpose for the latest version (since version 25).

  • Domain: ai.onnx

  • Since version: 13

Returns a transpose of the input tensor. (Similar to numpy.transpose). The optional attribute perm must be a permutation of the dimensions of the input tensor. Axis i of the output tensor corresponds to the axis perm[i] of the input tensor. For example, when perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape will be (2, 1, 3). When perm=(1, 2, 0), given an input tensor of shape (1, 2, 3), the output shape will be (2, 3, 1). If the attribute perm is omitted, its default value is (n-1, ..., 0), where n is the rank of the input tensor.

Inputs

  • data (T): An input tensor.

Outputs

  • transposed (T): Transposed output.

Attributes

  • perm (int[]): A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given.

Type Constraints

  • T: Constrain input and output types to all tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Examples#

test_cc_transpose_all_permutations_0

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [0, 1, 2]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

test_cc_transpose_all_permutations_1

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [0, 2, 1]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(2, 4, 3), dtype=float32
    [[[-0.29525974, -0.8285298 ,  0.43578833],
      [-1.2979394 , -0.2209149 ,  0.1658331 ],
      [ 0.15624313,  0.8234235 , -2.3817322 ],
      [ 0.6064112 , -0.5142446 ,  1.183266  ]],

     [[ 1.9895338 ,  0.47558898, -0.28296357],
      [-1.2199961 , -2.5581644 , -0.18944317],
      [-0.33663332, -0.30646107,  1.0395067 ],
      [ 1.534093  , -1.0730894 , -0.8414997 ]]]

test_cc_transpose_all_permutations_2

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [1, 0, 2]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(3, 2, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ]],

     [[-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ]],

     [[ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

test_cc_transpose_all_permutations_3

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [1, 2, 0]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(3, 4, 2), dtype=float32
    [[[-0.29525974,  1.9895338 ],
      [-1.2979394 , -1.2199961 ],
      [ 0.15624313, -0.33663332],
      [ 0.6064112 ,  1.534093  ]],

     [[-0.8285298 ,  0.47558898],
      [-0.2209149 , -2.5581644 ],
      [ 0.8234235 , -0.30646107],
      [-0.5142446 , -1.0730894 ]],

     [[ 0.43578833, -0.28296357],
      [ 0.1658331 , -0.18944317],
      [-2.3817322 ,  1.0395067 ],
      [ 1.183266  , -0.8414997 ]]]

test_cc_transpose_all_permutations_4

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [2, 0, 1]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(4, 2, 3), dtype=float32
    [[[-0.29525974, -0.8285298 ,  0.43578833],
      [ 1.9895338 ,  0.47558898, -0.28296357]],

     [[-1.2979394 , -0.2209149 ,  0.1658331 ],
      [-1.2199961 , -2.5581644 , -0.18944317]],

     [[ 0.15624313,  0.8234235 , -2.3817322 ],
      [-0.33663332, -0.30646107,  1.0395067 ]],

     [[ 0.6064112 , -0.5142446 ,  1.183266  ],
      [ 1.534093  , -1.0730894 , -0.8414997 ]]]

test_cc_transpose_all_permutations_5

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [2, 1, 0]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[-0.29525974, -1.2979394 ,  0.15624313,  0.6064112 ],
      [-0.8285298 , -0.2209149 ,  0.8234235 , -0.5142446 ],
      [ 0.43578833,  0.1658331 , -2.3817322 ,  1.183266  ]],

     [[ 1.9895338 , -1.2199961 , -0.33663332,  1.534093  ],
      [ 0.47558898, -2.5581644 , -0.30646107, -1.0730894 ],
      [-0.28296357, -0.18944317,  1.0395067 , -0.8414997 ]]]

Outputs:
  transposed: shape=(4, 3, 2), dtype=float32
    [[[-0.29525974,  1.9895338 ],
      [-0.8285298 ,  0.47558898],
      [ 0.43578833, -0.28296357]],

     [[-1.2979394 , -1.2199961 ],
      [-0.2209149 , -2.5581644 ],
      [ 0.1658331 , -0.18944317]],

     [[ 0.15624313, -0.33663332],
      [ 0.8234235 , -0.30646107],
      [-2.3817322 ,  1.0395067 ]],

     [[ 0.6064112 ,  1.534093  ],
      [-0.5142446 , -1.0730894 ],
      [ 1.183266  , -0.8414997 ]]]

test_cc_transpose_default_perm

Node:
  Transpose(data) -> (transposed)
Inputs:
  data: shape=(2, 3), dtype=float32
    [[0., 1., 2.],
     [3., 4., 5.]]

Outputs:
  transposed: shape=(3, 2), dtype=float32
    [[0., 3.],
     [1., 4.],
     [2., 5.]]

test_cc_transpose_permuted_axes

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [1, 0, 2]
Inputs:
  data: shape=(2, 3, 4), dtype=float32
    [[[ 0.,  1.,  2.,  3.],
      [ 4.,  5.,  6.,  7.],
      [ 8.,  9., 10., 11.]],

     [[12., 13., 14., 15.],
      [16., 17., 18., 19.],
      [20., 21., 22., 23.]]]

Outputs:
  transposed: shape=(3, 2, 4), dtype=float32
    [[[ 0.,  1.,  2.,  3.],
      [12., 13., 14., 15.]],

     [[ 4.,  5.,  6.,  7.],
      [16., 17., 18., 19.]],

     [[ 8.,  9., 10., 11.],
      [20., 21., 22., 23.]]]

test_cc_transpose_permuted_axes_2

Node:
  Transpose(data) -> (transposed)
  Attributes:
    perm = [1, 2, 0]
Inputs:
  data: shape=(1, 2, 3), dtype=float32
    [[[0., 1., 2.],
      [3., 4., 5.]]]

Outputs:
  transposed: shape=(2, 3, 1), dtype=float32
    [[[0.],
      [1.],
      [2.]],

     [[3.],
      [4.],
      [5.]]]

Differences with previous version (1)#

SchemaDiff: Transpose (domain 'ai.onnx')

  • old version: 1

  • new version: 13

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]