Here is a code i wrote to find max value and its location in n number of file
I can print them in screen but dont know hoe to write them in a txt file. Could u help me
I can print them in screen but dont know hoe to write them in a txt file. Could u help me
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from numpy import loadtxt from numpy import max as max2 from os import listdir, chdir, getcwd from matplotlib.pylab import where # accesing to folder with hmax_00001 ... chdir( 'hmax' ) # obtain files list file1 = listdir(getcwd()) # obtain number of files n = len (file1) # read files, one by one for i in range (n): # load file d1 = loadtxt(file1[i]) # calculate max value h1max = max2(d1) # search position of max value px, py = where(h1max = = d1) # show data in screen print (file1[i], 'Max = ' ,h1max, ' loc = (' ,px[ 0 ], ',' ,py[ 0 ], ')' ) # delete variables del d1, h1max, px, py del i # return to folder initial chdir( '..' ) |