Turning 1D MVar into a diagonal matrix
回答済みHi,
I wonder if GUROBI has a function that creates a diagonal matrix out of a 1-D MVar. I essentially have as optimization variables these "row-wise 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 row-scaled 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 row-wise by an 1D MVar?
Thanks!
0
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Gabriel,
I think
E*K.reshape(N_1,1)
is what you are looking for.
- Riley
0 -
Thanks Riley Clement ! That works
0
投稿コメントは受け付けていません。
コメント
3件のコメント