title: SymPy : creating a numpy function from diagonal matrix that takes a numpy array
body: <p>Building on an example I've found <a href="https://stackoverflow.com/questions/33104953/how-to-replace-the-the-diagonal-elements-of-a-matrix-by-a-vector-in-sympy">here</a>, I am trying to create a function from a diagonal matrix that was created using <code>sumpy.diag</code>      </p>
  
  <pre><code>myM = Matrix([
  [x1, 4, 4],
  [4, x2, 4],
  [4, 4, x3]])  
  </code></pre>
  
  <p>Where this was created using this routine for example:</p>
  
  <pre><code>import sympy as sp
  import numpy as np
  
  x1 = sp.Symbol('x1')
  x2 = sp.Symbol('x2')
  x3 = sp.Symbol('x3')
  X = sp.Matrix([x1, x2, x3])
  
  myM = 4 * sp.ones(3, 3)
  sp.diag(*X) + myM - sp.diag(*np.diag(myM))
  </code></pre>
  
  <p>now I will like to create a function, using <code>lambdify</code> of <code>ufuncify</code>, that takes a <code>numpy.array</code> or length 3 (like <code>np.array([0.1,0.2,0.3])</code>)as an input, and gives the output as a matrix according to <code>myM</code> </p>
  
  <pre><code>myM = Matrix([
  [0.1, 4, 4],
  [4, 0.2, 4],
  [4, 4, 0.3]])  
  </code></pre>
  
  <p>Eventually I need to create a Jacobian matrix symbolically using this method:
   <a href="https://i.stack.imgur.com/U6d0J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U6d0J.png" alt="Jacobian"></a>
  And as the functional form may change during the calculation, then having the Jacobian calculated symbolically would be very useful.</p>