mindspore.ops.InvertPermutation
- class mindspore.ops.InvertPermutation(*args, **kwargs)[source]
Computes the inverse of an index permutation.
Given a tuple input, this operation inserts a dimension of 1 at the dimension This operation calculates the inverse of the index replacement. It requires a 1-dimensional tuple x, which represents the array starting at zero, and swaps each value with its index position. In other words, for the output tuple y and the input tuple x, this operation calculates the following: \(y[x[i]] = i, \quad i \in [0, 1, \ldots, \text{len}(x)-1]\).
Note
These values must include 0. There must be no duplicate values and the values can not be negative.
- Inputs:
input_x (Union(tuple[int], list[int]) - The input is constructed by multiple integers, i.e., \((y_1, y_2, ..., y_S)\) representing the indices. The values must include 0. There can be no duplicate values or negative values. Only constant value is allowed. The maximum value must be equal to length of input_x.
- Outputs:
tuple[int]. It has the same length as the input.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> invert = ops.InvertPermutation() >>> input_data = (3, 4, 0, 2, 1) >>> output = invert(input_data) >>> print(output) (2, 4, 3, 0, 1)