Сначала поместите его в список, а затем сложите.
h = 10
w = 20
c = 30
l = []
for i in range(5):
result_3d = np.zeros((h, w, c)) #fake calculation
l.append(result_3d)
res = np.stack(l, axis=-1)
res.shape # (10, 20, 30, 5)
# move stacked axis around ...
np.transpose(res, (3,0,1,2)).shape # (5, 10, 20, 30)
Если вы хотите обновить в цикле, вы можете сделать это:
res = ''
for i in range(5):
result_3d = np.zeros((h, w, c)) #fake calculation
if type(res) is str:
res = np.array([result_3d]) # add dimension
continue
res = np.vstack((res, np.array([result_3d]))) # stack on that dimension
res.shape # (5, 10, 20, 30)