Say I have this object array containing lists of the same length:
>>> a = np.empty(2, dtype=object)
>>> a[0] = [1, 2, 3, 4]
>>> a[1] = [5, 6, 7, 8]
>>> a
array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=object)
How can I convert this to a numeric 2D array?
>>> a.shape (2,) >>> b = WHAT_GOES_HERE(a) >>> b array([[1, 2, 3, 4], [5, 6, 7, 8]]) >>> b.shape (2, 4)How can I do the reverse?
Does it get easier if my
aarray is annp.arrayofnp.arrays, rather than annp.arrayoflists?>>> na = np.empty(2, dtype=object) >>> na[0] = np.array([1, 2, 3, 4]) >>> na[1] = np.array([5, 6, 7, 8]) >>> na array([array([1, 2, 3, 4]), ([5, 6, 7, 8])], dtype=object)
ValueError: setting an array element with a sequence.-astypecan't reshape