I'm trying to create a numpy array that looks like
array([[list([]), list([])],
[list([]), list([])],
[list([]), list([])]], dtype=object)
This array has shape (3,2)
. However, whenever I do
np.array([[list(), list()], [list(), list()], [list(), list()]])
I end up getting
array([], shape=(3, 2, 0), dtype=float64)
How do I solve this?
np.array
tries to create multidimensional numeric (or string) array, which it can do if all the input lists have a consistent size. It's only when the sizes differ that it falls back on creating an object dtype array (or in some cases raising an error). – Moll