Python Forum
Problem in solving optimization problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in solving optimization problem
#1
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:

sigma1m=np.matrix(sigma1)
gamma1=model.addMVar(n, name="gamma1")
for i in range(n):      
model.addConstr(gamma1*sigma1m[:,i]==0)
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.
Error:
TypeError: only size-1 arrays can be converted to Python scalars
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help solving a problem rufenghk 7 2,523 Jun-04-2022, 10:15 PM
Last Post: rufenghk
  Problem with "Number List" problem on HackerRank Pnerd 5 2,034 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,691 Jan-30-2022, 10:53 PM
Last Post: quest
  Problem with csv giorgosmarga 4 2,321 Mar-18-2021, 11:07 AM
Last Post: giorgosmarga
  optimization problem for dataframe manipulation fimmu 0 1,438 Aug-31-2020, 06:02 PM
Last Post: fimmu
  Map() problem pyzyx3qwerty 4 2,458 May-16-2020, 01:35 PM
Last Post: pyzyx3qwerty
  else problem MJB 3 8,198 May-02-2020, 02:30 PM
Last Post: Yoriz
  Need Help With A Problem I Have Come Across finndude 10 3,712 Apr-14-2020, 01:15 PM
Last Post: finndude
  Pip problem Jules 5 10,544 Mar-25-2020, 12:21 AM
Last Post: Larz60+
  Problem with a language word problem baobei 17 7,739 Mar-21-2020, 04:22 PM
Last Post: baobei

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020