I have an arbitrarily deeply nested list, with varying length of elements
my_list = [[[1,2],[4]],[[4,4,3]],[[1,2,1],[4,3,4,5],[4,1]]]
I want to convert this to a valid numeric (not object) numpy array, by padding out each axis with NaN. So the result should look like
padded_list = np.array([[[ 1, 2, nan, nan],
[ 4, nan, nan, nan],
[nan, nan, nan, nan]],
[[ 4, 4, 3, nan],
[nan, nan, nan, nan],
[nan, nan, nan, nan]],
[[ 1, 2, 1, nan],
[ 4, 3, 4, 5],
[ 4, 1, nan, nan]]])
How do I do this?
See Question&Answers more detail:
os