title: Factorial of a matrix elementwise with Numpy
body: <p>I'd like to know how to calculate the factorial of a matrix elementwise. For example,</p>
  
  <pre><code>import numpy as np
  mat = np.array([[1,2,3],[2,3,4]])
  
  np.the_function_i_want(mat)
  </code></pre>
  
  <p>would give a matrix <code>mat2</code> such that <code>mat2[i,j] = mat[i,j]!</code>. I've tried something like</p>
  
  <pre><code>np.fromfunction(lambda i,j: np.math.factorial(mat[i,j]))
  </code></pre>
  
  <p>but it passes the entire matrix as argument for <code>np.math.factorial</code>. I've also tried to use <code>scipy.vectorize</code> but for matrices larger than 10x10 I get an error. This is the code I wrote:</p>
  
  <pre><code>import scipy as sp
  javi = sp.fromfunction(lambda i,j: i+j, (15,15))
  fact = sp.vectorize(sp.math.factorial)
  fact(javi)
  
  OverflowError: Python int too large to convert to C long
  </code></pre>
  
  <p>Such an integer number would be greater than 2e9, so I don't understand what this means.</p>