code: def _average_path_length(n_samples_leaf):
      """
      Taken from sklearn implementation of isolation forest:
      https://github.com/scikit-learn/scikit-learn/blob/fd237278e/sklearn/ensemble/_iforest.py#L480
      For each given number of samples in the array n_samples_leaf, this calculates average path length of unsucceesful
      BST search.
  
      Args:
          n_samples_leaf: array of number of samples (in leaf)
  
      Returns:
          array of average path lengths
      """
      n_samples_leaf_shape = n_samples_leaf.shape
      n_samples_leaf = n_samples_leaf.reshape((1, -1))
      average_path_length = np.zeros(n_samples_leaf.shape)
  
      mask_1 = n_samples_leaf <= 1
      mask_2 = n_samples_leaf == 2
      not_mask = ~np.logical_or(mask_1, mask_2)
  
      average_path_length[mask_1] = 0.0
      average_path_length[mask_2] = 1.0
      average_path_length[not_mask] = (
          2.0
          * (np.log(n_samples_leaf[not_mask] - 1.0) + np.euler_gamma)
          - 2.0
          * (n_samples_leaf[not_mask] - 1.0)
          / n_samples_leaf[not_mask]
      )
  
      return average_path_length.reshape(n_samples_leaf_shape)
  
imports: import numpy
  from onnxconverter_common.registration import register_converter
  from ..None import constants
  from .._tree_commons import get_parameters_for_sklearn_common, get_parameters_for_tree_trav_sklearn, get_tree_params_and_type, get_parameters_for_gemm_common
  from .._tree_implementations import TreeImpl, GEMMTreeImpl, TreeTraversalTreeImpl, PerfectTreeTraversalTreeImpl
label_desc: Use image node_id 1 for calling a global function with example usage: _average_path_length(n_samples_leaf) and returns: average_path_length