How to append data over loops

Viewed 36
for file in image_chunk:
    temp = mat73.loadmat(file)['image'] 
    print(temp.shape)


(10, 20, 3, 1000)
(10, 20, 3, 2000)
(10, 20, 3, 3000)

I have some data like this, I wanted to append or concatenate over the fourth dimension. how can I do that?

My result will be (10, 20, 3, 6000)

1 Answers

Convert it to a numpy array and do this:

import numpy as np
a=np.array([[10, 20, 3, 1000],
   [10, 20, 3, 2000],
   [10, 20, 3, 3000]])

  
print(np.sum(a[:,3]))

Edit- Since you changed your answer,

b=np.sum(a[:,3])
a[:,3]=b
print(a[1])

for i in range(len(a)-1):
   a=np.delete(a,i,0)
print(a)

to get your results

enter code here

Related