code: def segment_normalize(
      data: jnp.ndarray,
      segment_ids: jnp.ndarray,
      num_segments: Optional[int] = None,
      indices_are_sorted: bool = False,
      unique_indices: bool = False,
      eps=1e-8,
  ):
      """Normalizes data within each segment.
  
      Args:
        data: values whose z-score normalized values will be calculated.
          segment-wise.
        segment_ids: indices for segments.
        num_segments: total number of segments.
        indices_are_sorted: whether ``segment_ids`` is known to be sorted.
        unique_indices: whether ``segment_ids`` is known to be free of duplicates.
        eps: epsilon for numerical stability.
  
      Returns:
        array containing data normalized segment-wise.
      """
  
      means = segment_mean(
          data,
          segment_ids,
          num_segments,
          indices_are_sorted=indices_are_sorted,
          unique_indices=unique_indices,
      )[segment_ids]
      variances = segment_variance(
          data,
          segment_ids,
          num_segments,
          indices_are_sorted=indices_are_sorted,
          unique_indices=unique_indices,
      )[segment_ids]
      normalized = (data - means) * lax.rsqrt(
          jnp.maximum(variances, jnp.array(eps, dtype=variances.dtype))
      )
      return normalized
  
imports: import functools
  from typing import Any, Callable, Generator, Iterable, Iterator, List, Mapping, Optional, Sequence, Union
  import jax
  from jax import lax
  import jax.numpy
  import jax.tree_util
  from jraph._src import graph
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: segment_normalize(data, segment_ids, num_segments, indices_are_sorted, unique_indices, eps) and returns: normalized