python 2.7 - Making subarray from function on multiple arrays -


in 1 folder have 13 txt files have 3 columns of data t, x, y. use path in glob set multiple arrays data values. question if want create separate array each of main arrays (t, x, y)

for path in glob("f:\thermal motion\*.txt"): t, x, y = np.loadtxt(path, unpack=true) in range(len(x)):     d = ((x[i] - x[0])**2 + (y[i] - y[0])**2)**0.5 

so when print d, don't array list. want sort d arrays according original 13 files. data first file going through d 1 array, , on...

d looks float me, not array or list. if understand need correctly, need list of "d-values" each file you're reading in. let's want list of values associated name of file produced them simplicity; can reorder them want later. use list comprehension store values, , dict map file names lists of d values. this:

d_values = {} path in glob("f:\thermal motion\*.txt"):     t, x, y = np.loadtxt(path, unpack=true)      # add list of computed d values d_values dictionary.     d_list = []     in range(len(x)):         d = ((x[i] - x[0])**2 + (y[i] - y[0])**2)**0.5         d_list.append(d)     d_values[path] = d_list 

the example above verbose clarity. if writing code real, i'd use list comprehension rather explicit inner loop:

d_values = {} path in glob("f:\thermal motion\*.txt"):     t, x, y = np.loadtxt(path, unpack=true)      d_values[path] = [((x[i] - x[0])**2 + (y[i] - y[0])**2)**0.5                        in range(len(x))] 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -