Say I have an array of the shape:
import numpy as np
a = np.zeros(shape=(3, 4, 2))
which looks like:
print a
[[[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]]
[[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]]
[[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]]]
How do I create an empty list with the same shape, where every 0. element is replaced by an empty sub-list?
In the specific case shown above, it would look like:
[[[[], []]
[[], []]
[[], []]
[[], []]],
[[[], []]
[[], []]
[[], []]
[[], []]],
[[[], []]
[[], []]
[[], []]
[[], []]]]
but I need a way that works in general for arrays of any shape. Is there a built in function to do this?
sublist, do you mean Pythonlists, or numpyarrays? What do you intend to do with these emptysublists?list. In this question you can see what I need to do with these lists: stackoverflow.com/q/29300646/1391441