mindspore.ops.ReverseSequence
- class mindspore.ops.ReverseSequence(*args, **kwargs)[source]
Reverses variable length slices.
- Parameters
- Inputs:
x (Tensor) - The input to reverse, supporting all number types including bool.
seq_lengths (Tensor) - Must be a 1-D vector with int32 or int64 types.
- Outputs:
Reversed tensor with the same shape and data type as input.
- Raises
TypeError – If seq_dim or batch_dim is not an int.
- Supported Platforms:
Ascend
Examples
>>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), mindspore.float32) >>> seq_lengths = Tensor(np.array([1, 2, 3])) >>> reverse_sequence = ops.ReverseSequence(seq_dim=1) >>> output = reverse_sequence(x, seq_lengths) >>> print(output) [[1. 2. 3.] [5. 4. 6.] [9. 8. 7.]]