title: In numpy, calculating a matrix where each cell contains the product of all the other entries in that row
body: <p>I have a matrix</p>
  
  <pre><code>A = np.array([[0.2, 0.4, 0.6],
                [0.5, 0.5, 0.5],
                [0.6, 0.4, 0.2]])
  </code></pre>
  
  <p>I want a new matrix, where the value of the entry in row i and column j is the product of all the entries of the ith row of A, except for the cell of that row in the jth column.</p>
  
  <pre><code>array([[ 0.24,  0.12,  0.08],
         [ 0.25,  0.25,  0.25],
         [ 0.08,  0.12,  0.24]])
  </code></pre>
  
  <p>The solution that first occurred to me was</p>
  
  <pre><code>np.repeat(np.prod(A, 1, keepdims = True), 3, axis = 1) / A
  </code></pre>
  
  <p>But this only works so long as no entries have values zero.</p>
  
  <p>Any thoughts? Thank you!</p>
  
  <p>Edit: I have developed</p>
  
  <pre><code>B = np.zeros((3, 3))
  for i in range(3):
      for j in range(3):
          B[i, j] = np.prod(i, A[[x for x in range(3) if x != j]])
  </code></pre>
  
  <p>but surely there is a more elegant way to accomplish this, which makes use of numpy's efficient C backend instead of inefficient python loops?</p>