code: def test_csd_mean():
      """Test averaging frequency bins of CrossSpectralDensity."""
      csd = _make_csd()
  
      # Test different ways to average across all frequencies
      avg = [[9], [10], [11], [12], [13], [14]]
      assert_array_equal(csd.mean()._data, avg)
      assert_array_equal(csd.mean(fmin=None, fmax=4)._data, avg)
      assert_array_equal(csd.mean(fmin=1, fmax=None)._data, avg)
      assert_array_equal(csd.mean(fmin=0, fmax=None)._data, avg)
      assert_array_equal(csd.mean(fmin=1, fmax=4)._data, avg)
  
      # Test averaging across frequency bins
      csd_binned = csd.mean(fmin=[1, 3], fmax=[2, 4])
      assert_array_equal(
          csd_binned._data,
          [[3, 15], [4, 16], [5, 17], [6, 18], [7, 19], [8, 20]],
      )
  
      csd_binned = csd.mean(fmin=[1, 3], fmax=[1, 4])
      assert_array_equal(
          csd_binned._data,
          [[0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20]],
      )
  
      # This flag should be set after averaging
      assert csd.mean()._is_sum
  
      # Test construction of .frequency attribute
      assert csd.mean().frequencies == [[1, 2, 3, 4]]
      assert csd.mean(fmin=[1, 3], fmax=[2, 4]).frequencies == [
          [1, 2],
          [3, 4],
      ]
  
      # Test invalid inputs
      raises(ValueError, csd.mean, fmin=1, fmax=[2, 3])
      raises(ValueError, csd.mean, fmin=[1, 2], fmax=[3])
      raises(ValueError, csd.mean, fmin=[1, 2], fmax=[1, 1])
  
      # Taking the mean twice should raise an error
      raises(RuntimeError, csd.mean().mean)
  
imports: import pickle
  from itertools import product
  from os import path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from pytest import raises
  import mne
  from mne.channels import equalize_channels
  from mne.proj import Projection
  from mne.time_frequency import CrossSpectralDensity, csd_array_fourier, csd_array_morlet, csd_array_multitaper, csd_fourier, csd_morlet, csd_multitaper, csd_tfr, pick_channels_csd, read_csd, tfr_morlet
  from mne.time_frequency.csd import _sym_mat_to_vector, _vector_to_sym_mat
  from mne.utils import sum_squared
label_desc: Use image node_id 4 for calling a global function with example usage: test_csd_mean() without return types