1

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)
4

1 回答 1

0

我已经看到了这一点,我记得没有看到任何特殊处理。所以不,它不会引起任何问题

于 2020-12-02T22:14:08.553 回答