capturegraph.data.containers.utilities.outer
#
outer - Cartesian Product for Lists#
Create all combinations of items from multiple Lists, returning a
multi-dimensional nested List structure. Similar to zip(), but creates
the outer product instead of zipping element-wise.
Example
import capturegraph.data as cg
# Create all location/time combinations
locations = cg.List([loc_a, loc_b])
times = cg.List([t1, t2, t3])
# Outer product: 2x3 nested list
combos = cg.outer(location=locations, time=times)
# → List([
# List([{location: loc_a, time: t1}, {location: loc_a, time: t2}, {location: loc_a, time: t3}]),
# List([{location: loc_b, time: t1}, {location: loc_b, time: t2}, {location: loc_b, time: t3}]),
# ])
# Flatten for 1D iteration
flat = cg.flatten(combos)
# → List([{location: loc_a, time: t1}, {location: loc_a, time: t2}, ...])
Positional Arguments
Like zip(), outer() also supports positional arguments which are
accessed by index:
outer(*args, **kwargs)
#
Create a Cartesian product of Lists as nested List of Dicts.
Creates a multi-dimensional nested List structure where the nesting depth equals the number of arguments, and each leaf is a Dict with all the combined values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
T | List[T]
|
Positional Lists (accessed by index 0, 1, 2, ...). |
()
|
**kwargs
|
T | List[T]
|
Named Lists (accessed by name). |
{}
|
Returns:
| Type | Description |
|---|---|
List[Any]
|
Nested List of Dicts. The nesting corresponds to each input List, |
List[Any]
|
in the order provided. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no arguments are provided. |