title: Elementwise multiplication of several arrays in Python Numpy
body: <p>Coding some Quantum Mechanics routines, I have discovered a curious behavior of Python's NumPy. When I use NumPy's multiply with more than two arrays, I get faulty results. In the code below, i have to write:</p>
  
  <pre><code>f = np.multiply(rowH,colH)
  A[row][col]=np.sum(np.multiply(f,w))
  </code></pre>
  
  <p>which produces the correct result. However, my initial formulation was this:</p>
  
  <pre><code>A[row][col]=np.sum(np.multiply(rowH, colH, w))
  </code></pre>
  
  <p>which does not produce an error message, but the wrong result. Where is my fault in thinking that I could give three arrays to numpy's multiply routine?</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>from numpy.polynomial.hermite import Hermite, hermgauss
  import numpy as np
  import matplotlib.pyplot as plt
  
  dim = 3
  x,w = hermgauss(dim)
  A = np.zeros((dim, dim))
  #build matrix
  for row in range(0, dim):
      rowH = Hermite.basis(row)(x)
      for col in range(0, dim):
          colH = Hermite.basis(col)(x)
          #gaussian quadrature in vectorized form
          f = np.multiply(rowH,colH)
          A[row][col]=np.sum(np.multiply(f,w))
  print(A)
  </code></pre>
  
  <p><strong>::NOTE::</strong> this code only runs with <strong>NumPy 1.7.0</strong> and higher!</p>