当前位置:   article > 正文

Python中解决线性规划和二次型规划问题的CVXOPT模块_python cvxopt

python cvxopt

Python CVXOPT模块

Python中支持Convex Optimization(凸规划)的模块为CVXOPT,能够解决线性规划和二次型规划问题,其应用场景如SVM中的Hard Margin SVM。

Creating matrices

CVXOPT has separate dense and sparse matrix objects.

A dense matrix is created using the matrix() function; it can be created from a list (or iterator):

  1. >>>from cvxopt import matrix
  2. >>>A = matrix([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], (2,3))
  3. >>>print(A)
  4. [ 1.00e+00 3.00e+00 5.00e+00]
  5. [ 2.00e+00 4.00e+00 6.00e+00]
  6. >>>A.size
  7. (2, 3)

or from a list of lists, where each inner list represents a column of the matrix:

  1. >>>B = matrix([ [1.0, 2.0], [3.0, 4.0] ])
  2. >>>print(B)
  3. [ 1.00e+00 3.00e+00]
  4. [ 2.00e+00 4.00e+00]

More generally, the inner lists can represent block-columns.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/593220
推荐阅读
相关标签
  

闽ICP备14008679号