title: How to apply a function for each element in a matrix in Python?
body: <p>I have a matrix of triangles where each line has 3 verticies:
  elementSet:</p>
  
  <pre><code>Element Number      Vertices 
      2           473    1159   917
      3           271    1026   816
  </code></pre>
  
  <p>And I also have a matrix of nodes that assign a 2d coordinated for every vertice
  nodeSet:</p>
  
  <pre><code>Vertice Number                 (X,Y)
  917             5.487167292060809 2.195789288329368 
  271             5.448888739433895 2.38822856765269 
  </code></pre>
  
  <p>I've written some methods to handle the area calculation, they are contained in a class:</p>
  
  <pre><code>  def findArea(self):
          self.elementsArea = nu.zeros((self.elementSet.shape[0],1))
          self.elementsArea[:] = self.calcArea(*self.elementSet[:,-3:])
  
    #Calculate the area of 3 points
    def calcArea (self,p1,p2,p3):
        [p1,p2,p3] = [self.nodeCoord(p1),self.nodeCoord(p2),self.nodeCoord(p3)]
  
        return 0.5*abs(p1[Xc]*(p2[Yc] - p3[Yc]) + p2[Xc]*(p3[Yc]-p1[Yc]) + p3[Xc]*(p1[Yc] - p2[Yc]))
  
  
    # returns the vertices of a point
    def nodeCoord(self, point):
          return(self.nodeSet[point-1,-3:-1]) 
  </code></pre>
  
  <p>where the function <code>calcArea</code> works fine but I want to apply a function to every element of a matrix and assign to another matrix without using a loop. </p>
  
  <p>I have to write something like:</p>
  
  <pre><code>A[:] = func(B[:])
  </code></pre>
  
  <p>In <code>def findArea()</code> I tried to do something like this but it gives me the following error:</p>
  
  <pre><code>calcArea() takes 4 positional arguments but 2171 were given
  </code></pre>
  
  <p>I wanna use calcArea() to calculate the area passing arrays as arguments the same way I did in this exemple:</p>
  
  <pre><code>import numpy as np
  
  
  def test(x,y):
      return x*y
  
  f = np.array([[1,2,5,6,7] , [3,4,9,6,7] ,[6,7,23,34,32]])
  
  print(test(f[0,:],f[1,:]))
  </code></pre>
  
  <p>I am trying to apply calcArea method but I am getting now only a 2 dimmensions array when I was suppose to get an array the same dimmension the original vectors</p>
  
  <pre><code>a.calcArea(f[0,:],f[1,:],f[2,:])
   array([ 7.5,  0. ])
  </code></pre>