def sparse2cvxopt(value):
 import cvxopt
 if isinstance(value, (np.ndarray, np.matrix)):
  return cvxopt.sparse(cvxopt.matrix(value.astype('float64')), tc='d')
 elif sp.issparse(value):
  value = value.tocoo()
  return cvxopt.spmatrix(value.data.tolist(), value.row.tolist(), value.col.tolist(), size=value.shape, tc='d')

def sparse2cvxopt ( value ) : import cvxopt if isinstance ( value , ( np . ndarray , np . matrix ) ) : return cvxopt . sparse ( cvxopt . matrix ( value . astype ( 'float64' ) ) , tc = 'd' ) elif sp . issparse ( value ) : value = value . tocoo ( ) return cvxopt . spmatrix ( value . data . tolist ( ) , value . row . tolist ( ) , value . col . tolist ( ) , size = value . shape , tc = 'd' )
converts a scipy sparse matrix to a cvxopt sparse matrix .