tensorstore.DimExpression.transpose[self, target: DimSelectionLike] DimExpression

Transposes the selected dimensions to the specified target indices.

A dimension range may be specified to reverse the order of all dimensions:

>>> transform = ts.IndexTransform(input_shape=[2, 3, 4],
...                               input_labels=["x", "y", "z"])
>>> transform[ts.d[:].transpose[::-1]]
Rank 3 -> 3 index space transform:
  Input domain:
    0: [0, 4) "z"
    1: [0, 3) "y"
    2: [0, 2) "x"
  Output index maps:
    out[0] = 0 + 1 * in[2]
    out[1] = 0 + 1 * in[1]
    out[2] = 0 + 1 * in[0]

Dimensions not in the selection retain their relative order and fill in the dimension indices not in target:

>>> transform = ts.IndexTransform(input_shape=[2, 3, 4],
...                               input_labels=["x", "y", "z"])
>>> transform[ts.d['x', 'z'].transpose[0, 1]]
Rank 3 -> 3 index space transform:
  Input domain:
    0: [0, 2) "x"
    1: [0, 4) "z"
    2: [0, 3) "y"
  Output index maps:
    out[0] = 0 + 1 * in[0]
    out[1] = 0 + 1 * in[2]
    out[2] = 0 + 1 * in[1]

A single non-negative target index may be specified to reorder all of the selected dimensions to start at the specified index:

>>> transform = ts.IndexTransform(input_shape=[2, 3, 4, 5],
...                               input_labels=["a", "b", "c", "d"])
>>> transform[ts.d['a', 'd'].transpose[1]]
Rank 4 -> 4 index space transform:
  Input domain:
    0: [0, 3) "b"
    1: [0, 2) "a"
    2: [0, 5) "d"
    3: [0, 4) "c"
  Output index maps:
    out[0] = 0 + 1 * in[1]
    out[1] = 0 + 1 * in[0]
    out[2] = 0 + 1 * in[3]
    out[3] = 0 + 1 * in[2]

A single negative target index may be specified to order all of the selected dimensions to end at the specified index from end:

>>> transform = ts.IndexTransform(input_shape=[2, 3, 4, 5],
...                               input_labels=["a", "b", "c", "d"])
>>> transform[ts.d['a', 'd'].transpose[-1]]
Rank 4 -> 4 index space transform:
  Input domain:
    0: [0, 3) "b"
    1: [0, 4) "c"
    2: [0, 2) "a"
    3: [0, 5) "d"
  Output index maps:
    out[0] = 0 + 1 * in[2]
    out[1] = 0 + 1 * in[0]
    out[2] = 0 + 1 * in[1]
    out[3] = 0 + 1 * in[3]
Parameters:
target: DimSelectionLike

Target dimension indices for the selected dimensions. All dimensions must be specified by index. Labels are not permitted. If the dimension selection has k > 1 dimensions, a single non-negative index i is equivalent to i:i+k; a single negative index -i is equivalent to -i-k:-i.

Returns:

Dimension expression with the transpose operation added.