<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def channel_interpolate(layer1, n_channel1, layer2, n_channel2):
 """Interpolate between layer1, n_channel1 and layer2, n_channel2. Optimize for a convex combination of layer1, n_channel1 and layer2, n_channel2, transitioning across the batch. Args: layer1: layer to optimize 100% at batch=0. n_channel1: neuron index to optimize 100% at batch=0. layer2: layer to optimize 100% at batch=N. n_channel2: neuron index to optimize 100% at batch=N. Returns: Objective """

  def inner(T):
    batch_n = T(layer1).get_shape().as_list()[0]
    arr1 = T(layer1)[..., n_channel1]
    arr2 = T(layer2)[..., n_channel2]
    weights = (np.arange(batch_n)/float(batch_n-1))
    S = 0
    for n in range(batch_n):
      S += (1-weights[n]) * tf.reduce_mean(arr1[n])
      S += weights[n] * tf.reduce_mean(arr2[n])
    return S
  return inner