python - getting error to save the Matrix in txt file using numpy numpy -


i have written code make array=>

import numpy np = np.array([[[1,3],[1,4]],[[1,4],[6,9]]]) np.savetxt('test.txt',a,fmt='%d') 

and getting 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: number required, not numpy.ndarray

during handling of above exception, 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') , format specifier ('%d %d')

how save array integer in file using numpy?

there old thread on problem

saving numpy array csv produces typeerror mismatch

if check, array 3d array causing issue

1. if translate 2d work

import numpy np = np.array([[[1,3],[1,4]],[[1,4],[6,9]]]) np.savetxt('test.txt',a.reshape(-1,a.shape[-1]),fmt="%d")

2. if write 1 row @ time work too

but have issues reading back

my suggestion, write dict/json , convert numpy after reading


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -