gpt4 book ai didi

python - 如何将 3d astropy 表写入文件

转载 作者:太空宇宙 更新时间:2023-11-04 05:52:01 25 4
gpt4 key购买 nike

我有一个 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 astropy 表写入文件的方式是

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 表。

最佳答案

我能够使用 hdf5 格式做到这一点:

param_table.write(param.h5, format='hdf5')

关于python - 如何将 3d astropy 表写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29826828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com