title: Function that acts on all elements of numpy array?
body: <p>I wonder if you can define a function to act on all elements of a 1-D numpy array simultaneously, so that you don't have to loop over the array. Similar to the way you can, for example, square all elements of an array without looping. An example of what I'm after is to replace this code:</p>
  
  <pre><code>A = np.array([ [1,4,2], [5,1,8], [2,9,5], [3,6,6] ])
  B = []
  
  for i in A:
      B.append( i[0] + i[1] - i[2] )
  
  B = array(B)
  print B
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&gt;&gt;&gt; array([3, -2, 6, 3])
  </code></pre>
  
  <p>With something like:</p>
  
  <pre><code>A = np.array([ [1,4,2], [5,1,8], [2,9,5], [3,6,6] ])
  
  def F(Z):
      return Z[0] + Z[1] - Z[2]
  
  print F(A)
  </code></pre>
  
  <p>So that the output is something like:</p>
  
  <pre><code>&gt;&gt;&gt; array( [ [3] , [-2], [6], [3] ] )
  </code></pre>
  
  <p>I know the 2nd code won't produce what I'm after, but I'm just trying to give an idea of what I'm talking about. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>I used the function above just as a simple example. The real function I'd like to use is something like this:</p>
  
  <pre><code> from numpy import linalg as LA
  
   def F(Z):
       #Z is an array of matrices
       return LA.eigh(Z)[0]
  </code></pre>
  
  <p>So I have an array of 3x3 matrices, and I'd like an output array of their eigenvalues. And I'm wondering if it's possible to do this in some numpythonic way, so as not to have to loop over the array. </p>