Studio Yotsuba
Back to Node List

Cartesian Product

cartesian_product

Builds every combination between list or palette A and B

Reviewed
Guide available

Input Ports

NameTypeDescription
A
a
Any
Required
First source list or palette
B
b
Any
Required
Second source list or palette

Output Ports

NameTypeDescription
Entries
entries
List<Map>
List of every { a, b } combination
Count
count
Int
Number of generated combinations

Overview

Creates every combination of two lists. It mechanically expands multiple axes of variation, such as "2 sizes × 3 colors = 6 combinations." A typical use is directly before batch production with batch_render.

Usage tips

  • The go-to batch-production chain is variant_range (strength) + seed_range (seed) → cartesian_product → batch_render. It produces "5 strength levels × 4 seeds = 20 images" in one pass.
  • The number of entries grows multiplicatively (a.len() × b.len()). To add a third axis, pass the output through another Cartesian Product, but watch for a combinatorial explosion.
  • If you only need corresponding pairs, use list_zip to avoid increasing the number of entries.

Related nodes

  • list_zip — corresponding pairs instead of every combination
  • variant_range / seed_range — generate candidates for each axis
  • batch_render — batch-produce the expanded results
  • list_map — post-process the combination table

Read this first

  • ListZip combines items at the same index, while CartesianProduct creates every combination.
  • 2 entries × 3 entries produces 6 entries.

Start with this example

Provide these two lists:

a = ["small", "large"]
b = ["red", "blue", "green"]

The resulting entries value is:

[
  { "index": 0, "a_index": 0, "b_index": 0, "a": "small", "b": "red" },
  { "index": 1, "a_index": 0, "b_index": 1, "a": "small", "b": "blue" },
  { "index": 2, "a_index": 0, "b_index": 2, "a": "small", "b": "green" },
  { "index": 3, "a_index": 1, "b_index": 0, "a": "large", "b": "red" },
  { "index": 4, "a_index": 1, "b_index": 1, "a": "large", "b": "blue" },
  { "index": 5, "a_index": 1, "b_index": 2, "a": "large", "b": "green" }
]
count = 6

How downstream nodes see it

When you feed these entries to ListMap or ListFilter, you can use the following fields directly in expressions:

  • index
  • a_index
  • b_index
  • a
  • b

For example:

a_index == 0
a + b

Working with Variant nodes

If a and b contain lists of VariantRecord values, a downstream BatchRender automatically collects and uses the snapshots inside a and b. This makes the node useful before multi-axis batch production, such as "strength candidates × seed candidates."

When to use it

  • To create every combination of seed candidates and candidates for another parameter
  • To represent a two-axis candidate space as explicit data
  • To build a batch candidate table before generating variant candidates

Notes

  • The result contains a.len() * b.len() entries, so the number of candidates can grow very quickly.
  • A Palette is treated as List<Color>.
Back to Node List