Tupledict to array
進行中Hello,
What is a quick way to convert the variable values of optimization (tupledict) to a regular array?
Thank you
-
正式なコメント
This post is more than three 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 why not try our AI Gurobot?. -
Could you give an example of what you are trying to do? If you want to create a Python list containing the solution values for a specific tupledict \( \texttt{x} \) of Var objects, you can use Model.getAttr() to retrieve the X attributes of the variables:
>>> model.getAttr('X', x.values())
[1.0, 1.0, 0.0, 0.0, 1.0]You could alternatively use a list comprehension:
>>> [v.X for v in x.values()]
[1.0, 1.0, 0.0, 0.0, 1.0]EDIT: As Hooman alluded to, \( \texttt{x} \) in the above code is a tupledict of Var objects that was created by calling Model.addVars(). The solution value of a Var object can be retrieved by accessing its X attribute.
1 -
Thank you Eli for your response. It was very helpful.
P.S: For others that might see this post later, it is important to note the difference between X and x in the above codes.
0
投稿コメントは受け付けていません。
コメント
3件のコメント