code: def test_op_batch_normalization_numpy(
      shape, spatial, device_id, precision
  ):
      # for some reason the numpy code below does not work in python 2.7
      import sys
  
      if sys.version_info[0] < 3:
          pytest.skip("Only works on Python 3+")
  
      dtype = PRECISION_TO_TYPE[precision]
      dev = cntk_device(device_id)
  
      if spatial:
          param_shape = (shape[0],)
          reduced_shape = shape[1:]
          reduce_dims = (0, 2, 3, 4)[0 : len(shape)]
      else:
          param_shape = (np.prod(shape),)
          reduced_shape = ()
          reduce_dims = (0,)
  
      batch_size = 3
      x = 10 * np.random.random((batch_size,) + shape).astype(dtype)
  
      init_scale = 1
      init_bias = 2
      init_mean = 3
      init_var = 4
      init_count = 2
      epsilon = 0.01
  
      i = C.input_variable(shape, dtype=dtype)
      scale = C.parameter(
          param_shape, init=init_scale, dtype=dtype, device=dev
      )
      bias = C.parameter(
          param_shape, init=init_bias, dtype=dtype, device=dev
      )
      run_mean = C.constant(
          init_mean, shape=param_shape, dtype=dtype, device=dev
      )
      run_var = C.constant(
          init_var, shape=param_shape, dtype=dtype, device=dev
      )
      run_count = C.constant(
          init_count, shape=(), dtype=dtype, device=dev
      )
      # use negative normalization_time_constant for easier exp_avg compute
      bn = C.batch_normalization(
          i,
          scale,
          bias,
          run_mean,
          run_var,
          spatial,
          normalization_time_constant=-1,
          epsilon=epsilon,
          running_count=run_count,
      )
      fwd = bn.eval(x, device=dev)
      y_fwd = (x - init_mean) / np.sqrt(
          init_var + epsilon
      ) * init_scale + init_bias
      assert np.allclose(y_fwd, fwd)
  
      bwd = bn.grad(x, wrt=bn.parameters, outputs=[bn], device=dev)
      exp_avg = batch_size / (init_count + batch_size)
  
      mean = np.mean(x, reduce_dims)
      mean_b = np.asarray(
          [[np.ones(reduced_shape) * x for x in mean]] * batch_size
      )
      reduced_count = batch_size * np.prod(reduced_shape)
      var = np.mean((x - mean_b) ** 2, reduce_dims)
      # the output variance is unbiased, while computation uses biased variance
      var_out = var * reduced_count / (reduced_count - 1)
      var_b = np.asarray(
          [[np.ones(reduced_shape) * x for x in var]] * batch_size
      )
      x_hat = (x - mean_b) / np.sqrt(var_b + epsilon)
      y = init_scale * x_hat + init_bias
  
      d_scale = np.sum(x_hat, reduce_dims)
      d_bias = np.sum(np.ones_like(x_hat), reduce_dims)
  
      assert np.allclose(y, bwd[1], atol=1e-6)
      assert np.allclose(
          d_scale.reshape(param_shape), bwd[0][scale], atol=1e-2
      )
      assert np.allclose(d_bias.reshape(param_shape), bwd[0][bias])
      assert np.allclose(
          init_var * (1 - exp_avg)
          + var_out.reshape(param_shape) * exp_avg,
          run_var.value,
      )
      assert np.allclose(
          init_mean * (1 - exp_avg)
          + mean.reshape(param_shape) * exp_avg,
          run_mean.value,
      )
      assert run_count.value == init_count + batch_size
  
imports: from __future__ import division
  import numpy
  import cntk
  import pytest
  from .ops_test_utils import unittest_helper, _test_unary_op, _test_binary_op, AA, precision, PRECISION_TO_TYPE, cntk_device
  from cntk.tests.test_utils import TOLERANCE_ABSOLUTE
  from cntk.internal.utils import eval
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
  from cntk.variables import Parameter, Constant
label_desc: Use image node_id 28 for calling a global function with example usage: test_op_batch_normalization_numpy(shape, spatial, device_id, precision) without return types