fn
cartesian_prod
→Tensorcartesian_prod(tensors: Tensor = ())Return the Cartesian product of the given 1-D tensors.
Generalisation of nested itertools.product to tensor inputs.
Given k tensors of sizes n_1, ..., n_k the output has shape
(prod(n_i), k).
Parameters
*tensorsTensor= ()Any number of 1-D tensors.
Returns
Tensor2-D tensor whose rows are all combinations of input elements, in lexicographic order.
Notes
For 2-D-style grid coordinates (separate per-axis outputs) use
meshgrid with indexing='ij'.
Examples
>>> import lucid
>>> a = lucid.tensor([1, 2])
>>> b = lucid.tensor([3, 4])
>>> lucid.cartesian_prod(a, b)
Tensor([[1, 3],
[1, 4],
[2, 3],
[2, 4]])