I am trying to solve an optimization problem on python with gurobi solver.
There is a constraint in which I am trying to multiply a 1*n variable vector with a single column of n*n matrix:
The code is as follows:
In this case, n=22
sigma1 is a 22*22 covariance matrix obtained from some data (sigma1=dfpart1.cov()). gamma1 is a variable vector consisting of 22 elements.
There is a constraint in which I am trying to multiply a 1*n variable vector with a single column of n*n matrix:
The code is as follows:
1 2 3 4 |
sigma1m = np.matrix(sigma1) gamma1 = model.addMVar(n, name = "gamma1" ) for i in range (n): model.addConstr(gamma1 * sigma1m[:,i] = = 0 ) |
sigma1 is a 22*22 covariance matrix obtained from some data (sigma1=dfpart1.cov()). gamma1 is a variable vector consisting of 22 elements.
Error: TypeError: only size-1 arrays can be converted to Python scalars