我CVXPY
通过 Julia 使用,这是一种使用列优先顺序将多维数组存储在内存中的语言。然而CVXPY
,它是用 Python 编写的,并接受Numpy
样式数组(默认为行优先)用作常量。
我想知道在翻译这样的 Python 代码时是否应该关心排序,例如使用 matrix A
:
import cvxpy as cp
import numpy as np
m = 30
n = 20
A = np.random.randn(m, n)
b = np.random.randn(m)
# Construct the problem.
x = cp.Variable(n)
objective = cp.Minimize(cp.sum_squares(A*x - b))
constraints = [0 <= x, x <= 1]
prob = cp.Problem(objective, constraints)
对朱莉娅:
using Random, PyCall
cp = pyimport("cvxpy")
m = 30
n = 20
A = randn(m, n)
b = randn(m)
# Construct the problem.
x = cp.Variable(n)
objective = cp.Minimize(cp.sum_squares(cp.matmul(A,x) - b))
constraints = [0 <= x, x <= 1]
prob = cp.Problem(objective, constraints)