Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. cvxMat = matrix(pdObj.as_matrix())
  2. pdObj[:]=np.array(cvxMat)
  3.  
  4. (matrix(pdObj.as_matrix()).T*cvxMat)[0]
  5.  
  6. >>> m1 = cvxopt.matrix([[1, 2, 3], [2, 3, 4]])
  7. >>> m2 = pd.DataFrame(np.array(m1)).T
  8.  
  9. >>> m1
  10. <3x2 matrix, tc='i'>
  11.  
  12. >>> m2.shape
  13. (2, 3)
  14.  
  15. >>> np.dot(m1,m2)
  16. array([[ 5, 8, 11],
  17. [ 8, 13, 18],
  18. [11, 18, 25]])
  19.  
  20. >>> m1 * m2
  21. 0 1 2
  22. 0 1 4 9
  23. 1 4 9 16
  24.  
  25. [2 rows x 3 columns]
  26.  
  27. In [90]: m1 = cvxopt.matrix([[1, 2, 3], [2, 3, 4]])
  28.  
  29. In [91]: m2 = np.matrix([[1, 2, 3], [2, 3, 4]])
  30.  
  31. In [92]: m1
  32. Out[92]: <3x2 matrix, tc='i'>
  33.  
  34. In [94]: m2.shape
  35. Out[94]: (2, 3)
  36.  
  37. In [95]: m1 * m2
  38. Out[95]:
  39. matrix([[ 5, 8, 11],
  40. [ 8, 13, 18],
  41. [11, 18, 25]])
  42.  
  43. def dot( A, B ):
  44. """ np.dot .value or .values if they exist """
  45. for val in "value values" .split():
  46. A = getattr( A, val, A ) # A.val or A
  47. B = getattr( B, val, B )
  48. A = np.asanyarray( A )
  49. B = np.asanyarray( B )
  50. try:
  51. np.dot( A, B )
  52. except ValueError:
  53. print >>sys.stderr, "error: can't dot shapes %s x %s" % (A.shape, B.shape)
  54. raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement