I have to flatten array of lists to 1d numpy array. I use this:
import numpy as np
orig = np.array([[1,2], [3]], dtype=object)
lst = []
for x in orig:
lst.extend(x)
result = np.array(lst) # makes array([1, 2, 3])
Is there a standard numpy function or method to do this (similar to np.flatten)?
np.hstack(orig.ravel())np.hstack(orig)! Turns out hstack allows arbitrary size internal arrays for 1d dimensional datahstacktreats the argument as a list of arrays - split on the first dimension.