Skip to content Skip to sidebar Skip to footer

Copy NumPy Matrix Into NumPy Array

I am using cvxpy to solve an optimization problem. I want to store the output, a matrix into a ndarray. This is the reduced test case. a representing the returned value from cvxpy.

Solution 1:

One simple way would be to use a list of the column index for indexing into z and then simply assign the NumPy matrix a there -

z[:,[0]] = a

Another way would be to use the transpose of the matrix a, which would be a row vector to assign into the sliced version of the first column in z -

z[:,0] = a.T

Post a Comment for "Copy NumPy Matrix Into NumPy Array"