cartesian products?

daren.r's Avatar


25 Aug, 2020 08:04 PM

coming from a SQL background, im not sure what it's called.. is there an effective way to do a cartesian product of two lists?


(x,y,z) , (1,2,3) becomes...

x1, x2, x3
y1, y2, y3
z1, z2, z3

i can do this manually now with a counter / range / shift .. but im not sure if theres something else i might be missing

  1. Support Staff 1 Posted by john on 26 Aug, 2020 12:36 AM

    john's Avatar

    Hi Daren,

    I made a simple Cartesian Product node for you (technically a subnetwork). See zip file and two screenshots (attached).

    If you look inside the cart_prod node you will see that it's absurdly simple: all I do is concatenate the two lists (with an optional delimiter).

    But there is a subtle trick needed to make this work. If you select the node and open the MetaData dialog, then select the set 1 and set 2 ports, you will see that the range for set 1 is list while the range for set 2 is value.

    This means that the node sucks in the entire set 1 list and then fires once for each item in set 2. Each time it fires it produces concatenations (ordered pairs) of every item from set 1 with one item from set 2. The end result is a single list with all combinations.

    This is a wonderful example of the way subnetworks work. Their main purpose is not so much to encapsulate nodes, but rather to choreograph the flow of data. This takes a little getting used to, but is very powerful.

    I provide two examples. You can feed the node strings or numbers, but both lists will be treated as strings. The first case shows the Cartesian Product of {x,y,z} with {1,2,3,4} with no delimiter. The second case joins two different sets of 10 random numbers and uses a comma delimiter. Although the output is a list of strings, you can treat them a points (comma-separated pairs of values) and use that to plot an arrangement of 100 dots.

    Thanks for an interesting question. Keep them coming!


  2. 2 Posted by daren.r on 29 Sep, 2020 03:19 AM

    daren.r's Avatar

    Thank you!

  3. daren.r closed this discussion on 23 Feb, 2023 01:58 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

03 Mar, 2024 04:34 AM
23 Feb, 2024 07:39 PM
23 Feb, 2024 10:02 AM
22 Feb, 2024 05:51 AM
21 Feb, 2024 05:27 PM


21 Feb, 2024 04:49 PM
16 Feb, 2024 05:24 PM
06 Feb, 2024 04:45 AM
19 Jan, 2024 09:50 AM
13 Jan, 2024 03:47 AM
05 Jan, 2024 05:10 PM