mindspore.ops.combinations
- mindspore.ops.combinations(input, r=2, with_replacement=False)[source]
Returns all r-length subsequences of input Tensor.
When with_replacement is set to
False
, it works similar to Python's itertools.combinations, and when with_replacement is set toTrue
, it behaves like itertools.combinations_with_replacement.- Parameters
- Returns
Tensor, contains all possible combinations of elements sampled from input Tensor.
- Raises
TypeError – If input is not a tensor.
TypeError – If r is not an int.
TypeError – If with_replacement is not bool.
ValueError – If input is not one-dimensional.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> from mindspore import Tensor, ops >>> input = Tensor([1, 3, -1, 0, 4]) >>> output = ops.combinations(input) >>> print(output.asnumpy()) [[ 1 3] [ 1 -1] [ 1 0] [ 1 4] [ 3 -1] [ 3 0] [ 3 4] [-1 0] [-1 4] [ 0 4]]