我有一个3d astropy表,我想写一个文件。 我通过将3d numpy数组转换为astropy表并添加一些列名来创建它。
这是我的表的示例输出。每行的每列中的数组表示第三维。
m_star [14] m_bh [14] ... exit_flag [14]
float64 float64 ... float64
------------------------- ------------------------ ... --------------
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 0.0 .. 0.0
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 0.0 .. 0.0
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 0.0 .. 0.0
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 0.0 .. 0.0
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 0.0 .. 0.0
3.9782e+32 .. 2.18801e+33 1.9891e+36 .. 1.9891e+38 ... 6.0 .. 6.0
我将2d天文数据表写入文件的方式是
param_table.write(param.txt, format='ascii')
但是当我尝试将3d astropy表写入文件时,收到错误:
Traceback (most recent call last):
File "/Users/astromonerd/HLX1/src/make_dat.py", line 86, in <module>
dat_table.write(run_dir + '/' + 'dat.txt', format='ascii')
File "/usr/local/lib/python2.7/site-packages/astropy/table/table.py", line 1906, in write
io_registry.write(self, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/astropy/io/registry.py", line 374, in write
writer(data, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/astropy/io/ascii/connect.py", line 29, in write_asciitable
return write(table, filename, **kwargs)
File "/usr/local/lib/python2.7/site-packages/astropy/io/ascii/ui.py", line 458, in write
writer.write(table, output)
File "/usr/local/lib/python2.7/site-packages/astropy/io/ascii/fastbasic.py", line 125, in write
self._write(table, output, {})
File "/usr/local/lib/python2.7/site-packages/astropy/io/ascii/fastbasic.py", line 139, in _write
writer.write(output, header_output, output_types)
File "astropy/io/ascii/cparser.pyx", line 986, in astropy.io.ascii.cparser.FastWriter.write (astropy/io/ascii/cparser.c:17696)
TypeError: unhashable type: 'list'
关键是能够通过另一个模块读取文件并检索astropy表。
答案 0 :(得分:1)
我能够使用hdf5格式执行此操作:
param_table.write(param.h5, format='hdf5')