Oct-25-2021, 10:23 PM
(This post was last modified: Oct-25-2021, 10:25 PM by silvialecc.)
Hello everyone, I work in a CNN project for my thesis and I have problem with my Python code. I hope that somebody can help me. Thank you.
I would like to take two .cvs files with the same name (each is a 9x9 matrix) from a folder and create a unique file of the size 9x9x2 and save it in another folder.
This is my code, right now the problem is that the final file has been saved as a 9x18 instead of 9x9x2.
I would like to take two .cvs files with the same name (each is a 9x9 matrix) from a folder and create a unique file of the size 9x9x2 and save it in another folder.
This is my code, right now the problem is that the final file has been saved as a 9x18 instead of 9x9x2.
import os, glob from collections import defaultdict dirs = ['/content/drive/MyDrive/Colab Notebooks/Nuova cartella/mu1/real', '/content/drive/MyDrive/Colab Notebooks/Nuova cartella/mu1/imag'] file_pattrn = r'*.csv' unique_files = defaultdict(list) for d in dirs: for i in glob.iglob(os.path.join(d, file_pattrn)): unique_files[os.path.basename(i)].append(i) destination = '/content/drive/MyDrive/Colab Notebooks/New_Dataset' for unique_filename, copies in unique_files.items(): with open(os.path.join(destination, unique_filename), 'w') as f: for copy in copies: with open(copy, 'r') as cp: for line in cp: f.write(line)