I have a list of lists like
list_ABC = [[A,B,C], [A,B,C], ...]
with 2D ndarrays A (2x2), B (2x3) and C (2x3).
Now, I'd like to convert the main list to a numpy array:
np.array(list_ABC)
However, I get the following error:
ValueError: could not broadcast input array from shape (2,2) into shape (2)
I need this conversion because I'd like to get
A_matrices = np.array(list_ABC)[:, 0]
B_matrices = np.array(list_ABC)[:, 1]
Such that I can finally obtain a ndarray containing all A-arrays (array(A,A,A,...)).
Unfortunately I can't get a clue from the value error message. Interestingly, if I only transpose matrix C with C.T
(making it a 3x2 matrix) no error is thrown.
Now, I could solve the problem by creating a list_A, list_B, list_C beforehand (and not list_ABC), but this doesn't feel as simple (constructing and appending to each list_A/B/C requires a few more lines of code). Similarly I could use other methods (e.g. using a dict with A,B,C keys containing a list of all A/B/C matrices), but nothing feels so simple like this solution.
A working example which throws the error:
import numpy as np
list = [[np.array([[ 476., 667.], [ 474., 502.]]), np.array([[ 343., 351., 449.], [ 352., 332., 292.]]), np.array([[ 328., 328., 294.], [ 367., 355., 447.]])], [np.array([[ 497., 546.], [ 456., 517.]]), np.array([[ 361., 342., 340.], [ 341., 304., 328.]]), np.array([[ 347., 313., 293.], [ 355., 333., 375.]])]]
np.array(list)
Thanks a lot!