title: Define loss function in keras using itertools
body: <p>I want to define a loss function, which represent the distance between the hidden layer output points. Firstly ,I wrote this without keras</p>
  
  <pre><code>import numpy as np
  import itertools
  pts = np.array([
      [10,10,10],
      [10,11,20],
      [20,11,30],
      [20,10,10],
      [10,10,20],
      ])
  diff = list(itertools.combinations(pts, 2))
  
  ptdiff = lambda (p1,p2): (np.sqrt(np.sum((p1 - p2) ** 2)))
  diffs = map(ptdiff, diff)
  np.mean(diffs)
  </code></pre>
  
  <p>I get the result. And I try this loss function in keras, <code>z</code> is the output of hidden layer, which is a matrix</p>
  
  <h1>define loss function</h1>
  
  <pre><code>def vae_loss(z):
      z_diff = list(itertools.combinations(z,2))
      ptdiff = lambda (p1,p2): (np.sqrt(np.sum((p1 - p2) ** 2)))
      z_diffs = map(ptdiff, z_diff)
      loss = K.mean(z_diffs)
      return loss
  </code></pre>
  
  <p>But it shows the <code>TypeError: 'Tensor' object is not iterable.</code>, I just wonder how can I fix this problem.</p>