numpy - How to populate an empty array selectively? -
i new python , have tried accomplish following little success:
in folder there *.columns files contain 5 (0-4) columns , 500 rows. need sum columns 1-4 on *.columns files , plot result against first column of of (all equal).
i created empty array in want paste first (0) column of array "x_array3" , columns 1-4 "y_array0". of them have same size (500l, 5l).
could please give me advice how proceed? lost right now.
christian
import glob import numpy np listoffiles = glob.glob("*.columns") y_array0 = 0 filename in listoffiles: y_array1 = np.genfromtxt(filename, skip_header = 1, usecols = (0, 1, 2, 3, 4)) y_array0 = y_array0 + y_array1 x_array3 = np.genfromtxt(listoffiles[0], skip_header = 1, usecols = (0, 1, 2, 3, 4)) empty_array = np.empty(shape=(500, 5)) ausgabe_array = ??? here i'm stuck ??? np.savetxt('sx_dos.out', ausgabe_array)
i have found working solution. read in columns single arrays , merge them @ end. still, can give me hint how 1 populates empty array selected items array (with size)?
chr.
import glob import numpy np listoffiles = glob.glob("*.columns") y_array_s0 = 0 y_array_p0 = 0 y_array_d0 = 0 y_array_f0 = 0 filename in listoffiles: y_array_s1 = np.genfromtxt(filename, skip_header = 1, usecols = (1)) y_array_s0 = y_array_s0 + y_array_s1 y_array_p1 = np.genfromtxt(filename, skip_header = 1, usecols = (2)) y_array_p0 = y_array_p0 + y_array_p1 y_array_d1 = np.genfromtxt(filename, skip_header = 1, usecols = (3)) y_array_d0 = y_array_d0 + y_array_d1 y_array_f1 = np.genfromtxt(filename, skip_header = 1, usecols = (4)) y_array_f0 = y_array_f0 + y_array_f1 x_array3 = np.genfromtxt(listoffiles[0], skip_header = 1, usecols = (0)) ausgabe_array = np.transpose(np.array((x_array3, y_array_s0, y_array_p0, y_array_d0,y_array_f0))) np.savetxt('sx_dos.out', ausgabe_array)
Comments
Post a Comment