Turning 1D MVar into a diagonal matrix
AnsweredHi,
I wonder if GUROBI has a function that creates a diagonal matrix out of a 1D MVar. I essentially have as optimization variables these "rowwise scaling factors" k, which I need to multiply by a given matrix to obtain a matrix M. So far I am trying to do:
#N_1 : int
#E : N_1 x N_1 2d csr sparse matrix
#Define our variables (N_1 scaling factors):
K = model.addMVar(shape=N_1, lb=0)
#Define the transformation M which is the rowscaled version of E:
M = diag(K) @ E
This last line doesn't really work. I also tried creating a sparse matrix by accessing K.X for example but the value wasn't available at the first pass. I also cannot use for loops as my N_1 value is very large.
Is there a way to diagonalize my 1D MVar K, or maybe is there a way to multiply a matrix rowwise by an 1D MVar?
Thanks!
0

Hi Gabriel,
I think
E*K.reshape(N_1,1)
is what you are looking for.
 Riley
0 
Thanks Riley Clement ! That works
0
Please sign in to leave a comment.
Comments
2 comments