This link suggests that we can use a Python list to add elements to it and convert it to numpy array using np.array with unknown length like this:
a = []
for x in y:
a.append(x)
a = np.array(a)
Let's say x is a numpy.ndarray with shape (h,w) but h and w are unknown, how can we add elements to second axis of ndarray a in a loop to make a becomes (h,w,d) where d is the number of iterations?
I understand we can use dstack to add elements together to become (h,w,d) but I am not too sure how to do this in a loop.
np.stack. WIth the defaultaxisvalue it behaves much likenp.array, but you can specify otheraxisvalues.