List - take elements with equal name

49 views Asked by At

Having a List like this:

[utc1_1.tga, utc1_2.tga, utc1_3.tga, utc1_4.tga,
 utc2_1.tga, utc2_2.tga, utc2_3.tga, utc2_4.tga,
 utc3_1.tga, utc3_2.tga, utc3_3.tga, utc3_4.tga,..]

I separated with this:

images = list(sorted([int(name.split('_')[0]) for name in directory_files]))

only timestamp names remain:

[utc1, utc1, utc1, utc1, utc2, utc2, utc2, utc2, utc3, utc3,...]

basically this list of images are numpy array. I would like to add the arrays with the equal timestamp.

You can check actual files at this google drive link

import cv2
from numpy import asarray
from multiprocessing import Process
import glob
from PIL import Image


images = glob.glob(f"{directory_files}*.tga")
for img_name in images:
  with open(img_name, 'rb') as ldr:
    print(img_name)
    image = Image.open(ldr)
    data = asarray(image)
    print(data.shape)


#images = list(sorted([int(name.split('_')[0]) for name in directory_files]))
#print(images)

#same_utc_arrays = 
#np.sum(same_utc_arrays)
    
1

There are 1 answers

1
Lucas Vale On

Not sure if I got it.

But if you want to separate them by timestamp. I would map them into a dict using timestamp as key.

Basically you would need to grab all different timestamp then start a dict, after that you could separate them by pushing to the respective timestamp key from the dict.