Guest User

Untitled

a guest
Jul 17th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import numpy as np
  2. from sympy import Matrix
  3. from scipy.optimize import minimize
  4.  
  5. def Testfunction(x):
  6. a = np.array([[1],[3],[6]]) #3x1 np.ndarray
  7. b = np.array([[2]]) #1x1 np.ndarray
  8. c = Matrix(x@x.T).vech() #3x1 mutable dense matrix
  9. y = np.transpose(np.subtract(a,c)) * b * np.subtract(a,c)
  10. return y #y should be a 1x1 np.ndarray
  11.  
  12. x0= np.array([[1],[3]]) # 2x1 np.ndarray
  13. print(Matrix(x0@x0.T).vech()) # works (3x1 mutable dense matrix)
  14. print(Testfunction(x0)) # works (3x3 instead of 1x1 np.ndarray though)
  15.  
  16. result = minimize(Testfunction, x0, method='nelder-mead', options={'xtol': 1e-8, 'disp': True}) #does not work as explained above
Add Comment
Please, Sign In to add comment