tag:support.nodebox.net,2012-11-01:/discussions/nodebox-2-3/6260-cartesian-productsNodeBox: Discussion 2023-02-23T01:58:52Ztag:support.nodebox.net,2012-11-01:Comment/485776142020-08-26T00:36:35Z2020-08-26T00:36:35Zcartesian products?<div><p>Hi Daren,</p>
<p>I made a simple Cartesian Product node for you (technically a subnetwork). See zip file and two screenshots (attached).</p>
<p>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).</p>
<p>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 <strong>list</strong> while the range for set 2 is <strong>value</strong>.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Thanks for an interesting question. Keep them coming!</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/485776142020-09-29T03:19:45Z2020-09-29T03:19:45Zcartesian products?<div><p>Thank you!</p></div>daren.r