mardi 3 novembre 2020

copy filestothe directory during each iteration of for loop

hii experts I have a small python script that runs over many data sets using for loop.

During each iteration using for loop it generates 50 data files and saves data in .npz format in the current directory. But i don't want to save data in the current directory instead i want to move 30 no of data files to dir1,10 no of data files to dir2 and another 10 no of data files to dir3 randomly during each iteration,where dir1,dir2 and dir3 should automatically created directories.i want to do same for each iteration of for loop.I tried the below script but donot getting suitable results.so here i need experts help.Thanks in advance.

import numpy as np
import glob
import os

filenames = [os.path.basename(x) for x in glob.glob("/home/ttr/Desktop/data/fck_rty_file_output_*_*.txt_*")]
for file in filenames:
  data1=np.loadtxt(file)

  for x in np.logspace(np.log10(0.1),np.log10(1.0),num=50):
          yy = x * np.random.randn(inpdata.shape[0],inpdata.shape[1])
          data2 =  data1 + yy
          np.savez(str(file)+'_'+str(x),dx=data1,dy=data2)
          
          ##move files
      .....



Aucun commentaire:

Enregistrer un commentaire