def _test(n): _generate(n, 3, "tmp.1") import time t0 = time.clock() f = open("tmp.1", "r") narrays = int(f.readline().split()[1]) print('found %d arrays in file' % narrays) for i in range(narrays): q = read(f) print('read an array with shape', q.shape) t1 = time.clock() print("read:", t1 - t0, "seconds\n") f.close() t0 = time.clock() f = open("tmp.2", "w") write(f, q) t1 = time.clock() print("write:", t1 - t0, "seconds") # compare with TableIO: try: import TableIO.TableIO as TableIO except: sys.exit(0) # exit silently t0 = time.clock() p = TableIO.readColumns("tmp.1", "#") # print 'p:', p t1 = time.clock() print("TableIO.readColumns:", t1 - t0, "seconds\n") t0 = time.clock() TableIO.writeArray("tmp.3", array(p)) t1 = time.clock() print("TableIO.writeArray:", t1 - t0, "seconds")
import TableIO.TableIO as TableIO except: print """ The TableIO Python module was not found. Make sure it is accessible in one of the directories in PYTHONPATH.""" sys.exit(1) try: infilename = sys.argv[1] outfilename = sys.argv[2] except: print "Usage:",sys.argv[0], "infile outfile"; sys.exit(1) # read column 0 into a NumPy array x, column 1 into y, # '#' is a valid comment sign in the input file: x, y = TableIO.readColumns(infilename, '#', [0, 1]) # transform y values: def myfunc(y): # y is a NumPy array return where(y < 0, 0.0, y**5*exp(-y)) y = myfunc(y) # transform x and y to a single NumPy array and dump: NumPy_xy = transpose(array([x,y])) TableIO.writeArray(outfilename, NumPy_xy) #TableIO.writeArray(outfilename, array([x,y])) # rows inst. of columns