0

I'm using pyscipopt to use scip and in my model I want to look at those columns of a matrix that correspond to the variables that are non-zero. However the expression A[:, np.nonzero(var_list)[0]] doesn't work as expected because the objects in the list var_list are variable objects, not their respective values, so they are all considered to be non-zero. How can I get around this?

Edit: This expression is in the objective I am trying to minimize, so something like [Model.getVal(x) for x in var_list] won't work.

yagod
  • 330
  • 1
  • 8

1 Answers1

0

You can make a new list only containing the values of var_list

new_list = [var.value for var in var_list]  # List containing the values
A[:, np.nonzero(new_list)[0]]
Yannick Funk
  • 1,319
  • 10
  • 23
  • I should clarify: This expression is in the objective I want to minimize, so I don't have the values yet at that point – yagod Nov 30 '20 at 09:34