scipy sparse matrix to cvxopt spmatrix?
问题 I need to convert a scipy sparse matrix to cvxopt's sparse matrix format, spmatrix, and haven't come across anything yet (the matrix is too big to be converted to dense, of course). Any ideas how to do this? 回答1: The more robust answer is a combination of hpaulj's answer and OferHelman's answer. def scipy_sparse_to_spmatrix(A): coo = A.tocoo() SP = spmatrix(coo.data.tolist(), coo.row.tolist(), coo.col.tolist(), size=A.shape) return SP Defining the shape variable preserves the dimensionality