torch.combinations
-
torch.combinations(input, r=2, with_replacement=False) → seq -
Вычисляет комбинации длины заданного тензора. Поведение аналогично поведению python’s
itertools.combinationsкогдаwith_replacementустановлено вFalse, иitertools.combinations_with_replacementкогдаwith_replacementустановлено вTrue.- Параметры:
- Возвращает:
-
Тензор, эквивалентный преобразованию всех тензоров входных данных в списки, выполнению
itertools.combinationsилиitertools.combinations_with_replacementнад этими списками и, наконец, преобразованию получившегося списка в тензор. - Тип возвращаемого значения:
Пример:
>>> a = [1, 2, 3] >>> list(itertools.combinations(a, r=2)) [(1, 2), (1, 3), (2, 3)] >>> list(itertools.combinations(a, r=3)) [(1, 2, 3)] >>> list(itertools.combinations_with_replacement(a, r=2)) [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)] >>> tensor_a = torch.tensor(a) >>> torch.combinations(tensor_a) tensor([[1, 2], [1, 3], [2, 3]]) >>> torch.combinations(tensor_a, r=3) tensor([[1, 2, 3]]) >>> torch.combinations(tensor_a, with_replacement=True) tensor([[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]])
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/1.13/generated/torch.combinations.html