I have the following three numpy arrays:
a = np.array([ 1, 2, 3, 4, 2, 3, 4 ])
b = np.array([ [1], [2,3,4], [], [2,3,4] ])
c = np.array([ 1, [2,[3,4]], [], [2,3,4] ])
How can I use a single function f that would work on all three arrays, returning the values in all sublists, in unaltered order and unaltered type?
So the answer should be f(a) == f(b) == f(c) == a.
I found the following trick here (Concatenation of inner lists or ints):
def f(b):
np.array([a for x in np_array for a in (x if isinstance(x, list) else [x])])
But this does not work for array c.