code: def _precompute_statistics(self) -> numpy.ndarray:
      n_nodes = self._n_nodes
  
      # Holds for each node, its weighted average value and the sum of weights.
      statistics = numpy.empty((n_nodes, 2), dtype=numpy.float64)
  
      subspaces = numpy.array([None for _ in range(n_nodes)])
      subspaces[0] = self._search_spaces
  
      # Compute marginals for leaf nodes.
      for node_index in range(n_nodes):
          subspace = subspaces[node_index]
  
          if self._is_node_leaf(node_index):
              value = self._get_node_value(node_index)
              weight = _get_cardinality(subspace)
              statistics[node_index] = [value, weight]
          else:
              for child_node_index, child_subspace in zip(
                  self._get_node_children(node_index),
                  self._get_node_children_subspaces(
                      node_index, subspace
                  ),
              ):
                  assert subspaces[child_node_index] is None
                  subspaces[child_node_index] = child_subspace
  
      # Compute marginals for internal nodes.
      for node_index in reversed(range(n_nodes)):
          if not self._is_node_leaf(node_index):
              child_values = []
              child_weights = []
              for child_node_index in self._get_node_children(
                  node_index
              ):
                  child_values.append(statistics[child_node_index, 0])
                  child_weights.append(statistics[child_node_index, 1])
              value = numpy.average(child_values, weights=child_weights)
              weight = float(numpy.sum(child_weights))
              statistics[node_index] = [value, weight]
  
      return statistics
  
imports: from __future__ import annotations
  from functools import lru_cache
  import itertools
  from typing import List
  from typing import Set
  from typing import Tuple
  from typing import TYPE_CHECKING
  from typing import Union
  import numpy
label_desc: Use image node_id 5 for calling the _FanovaTree obj's underlying member method code with example usage: obj._precompute_statistics() and returns: statistics