Skip to content
Discussion options

You must be logged in to vote

You can make the array in a single pass through the postorder array, right?

total_nodes = np.zeros_like(tree.tree_sequence.num_nodes)
for u in tree.postorder():
     for v in tree.children(u):
           total_nodes[u] += total_nodes[v]
     total_nodes[u] += 1

Or such like?

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@hyanwong
Comment options

hyanwong Nov 17, 2022
Maintainer Author

@hyanwong
Comment options

hyanwong May 28, 2026
Maintainer Author

Answer selected by hyanwong
Comment options

You must be logged in to vote
1 reply
@hyanwong
Comment options

hyanwong Sep 29, 2022
Maintainer Author

Comment options

You must be logged in to vote
0 replies
Comment options

hyanwong
May 28, 2026
Maintainer Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants