# Make one tree the branch of another

Hi community,

I have two data trees:
IDX (for indices):
{0} = (N = 3) (e.g. 1, 3, 4)
{1} = (N = 2) (e.g. 5, 6)
{1} = (N = 5)
{2} = (N = 6)
{3} = (N = 7)
{4} = (N = 8)
{5} = (N = 9)
{6} = (N = 1)

Now, I want to us IDX to access branches of ADJ by index
[I Want] My resulting tree would be
{0:1} = (N = 5)
{0:3} = (N = 7)
{0:4} = (N = 8)
{1:5} = (N = 9)
{1:6} = (N = 1)
That is, branches IDX{0} retries from ADJ stays in a separate branch from what IDX{1} retrieved
[I Don’t Want] The problem is, when I do Tree Branch with Tree=ADJ, Path=IDX, the output is actually:
{1} = (N = 5)
{3} = (N = 7)
{4} = (N = 8)
{5} = (N = 9)
{6} = (N = 1)
It is as though my IDX got flattened on the way in! I get the same result even if I Graft IDX

Could you please give me some guidance on getting my desired result?

something like this might work, probably there are easier/faster ways…

1 Like

Thanks so much for your help inno!

This a great solution, as shown in the panels, where:
[tab]Data{0}[1] = 18, so in the result, {0:0} is ADJ_MATRIX{18}, ect.

Also, I notice that the Tree Branch function auto-flattens the input (sorry to repeat!)–flattening vs not-flattening made no difference.

This seems counter-intuitive compared to functions like List Item, which does take into account the tree structure of the Index input.

1 Like

I agree with you, also about the always flattened behavior of Tree Branch

if you are open to using plugins, there’s a super helpful set of “grouping” components in Metahopper, that allow you to group any king of data the very same way the Group component works on geometries

this allows to literally treat a branch as an element you can retrieve with list item: