I have written this code to make an array=>
import numpy as np
a = np.array([[[1,3],[1,4]],[[1,4],[6,9]]])
np.savetxt('test.txt',a,fmt='%d')
and getting this error =>
Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/numpy-1.11.2-py3.4-linux-x86_64.egg/numpy/lib/npyio.py", line 1158, in savetxt fh.write(asbytes(format % tuple(row) + newline)) TypeError: %d format: a number is required, not numpy.ndarray
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/dist-packages/numpy-1.11.2-py3.4-linux-x86_64.egg/numpy/lib/npyio.py", line 1162, in savetxt % (str(X.dtype), format)) TypeError: Mismatch between array dtype ('int64') and format specifier ('%d %d')
How to save the array as an integer in file using numpy?
a.reshape(-1, 2)
instead.np.savetxt('test.txt',a.reshape(-1,2),fmt='%d')
– Psidom