import tensorflow as tf

  """Computes mean and std for batch then apply batch_normalization on batch.

  Returns
  -------
  A tuple length of 3, (normalized_tensor, mean, variance).
  """
  mean, var = tf.nn.moments(
      x, reduction_axes, shift=None, name=None, keep_dims=False)
  if sorted(reduction_axes) == range(ndim(x))[:-1]:
    normed = tf.nn.batch_normalization(x, mean, var, beta, gamma, epsilon)
  else:
    # need broadcasting
    target_shape = []
    for axis in range(get_ndim(x)):
      if axis in reduction_axes:
        target_shape.append(1)
      else:
        target_shape.append(tf.shape(x)[axis])
