combinations

paddle. combinations ( x, r=2, with_replacement=False, name=None ) [source]

Compute combinations of length r of the given tensor. The behavior is similar to python’s itertools.combinations when with_replacement is set to False, and itertools.combinations_with_replacement when with_replacement is set to True.

Parameters
  • x (Tensor) – 1-D input Tensor, the data type is float16, float32, float64, int32 or int64.

  • r (int, optional) – number of elements to combine, default value is 2.

  • with_replacement (bool, optional) – whether to allow duplication in combination, default value is False.

  • name (str, optional) – Name for the operation (optional, default is None).For more information, please refer to Name.

Returns

out (Tensor). Tensor concatenated by combinations, same dtype with x.

Examples

>>> import paddle
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32')
>>> res = paddle.combinations(x)
>>> print(res)
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True,
       [[1, 2],
        [1, 3],
        [2, 3]])