Problem while writing array with np.savetxt

Dear list, whilst trying to write an array to disk I am coming across the following. What am I doing wrong? Surely f is a file handle? (python 3.4.3, numpy 1.9.2) import numpy as np a = np.arange(10.) with open('test.dat', 'w') as f: np.savetxt(f, a) --------------------------------------------------------------------------- TypeError Traceback (most recent call last)<ipython-input-57-cf77f423517e> in <module>() 2 a = np.arange(10.) 3 with open('test.dat', 'w') as f:----> 4 np.savetxt(f, a) /Users/anz/Documents/Andy/programming/dev3/lib/python3.4/site-packages/numpy/lib/npyio.py in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments) 1085 else: 1086 for row in X:-> 1087 fh.write(asbytes(format % tuple(row) + newline)) 1088 if len(footer) > 0: 1089 footer = footer.replace('\n', '\n' + comments) TypeError: must be str, not bytes -- _____________________________________ Dr. Andrew Nelson _____________________________________
participants (3)
-
Andrew Nelson
-
Eric Firing
-
Julian Taylor