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.
import numpy as np
z = np.zeros((3,7))
a = np.matrix("[1; 2; 3]")
z[0, 0] = a[0]
z[1, 0] = a[1]
z[2, 0] = a[2]
I would like to replace the last three lines with something better, but everything I try results in an error. E.g.,
>>> z[:, 0] = a
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: could not broadcast input array from shape (3,1) into shape (3)
>>> np.copyto(z[:, 0], a)
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: could not broadcast input array from shape (3,1) into shape (3)
I would appreciate a little help. Thank you.