gpt4 book ai didi

python - 将 astropy.table.columns 转换为 numpy 数组

转载 作者:行者123 更新时间:2023-12-02 20:39:30 25 4
gpt4 key购买 nike

我想绘制:

points = np.random.multivariate_normal(mean=(0,0), cov=[[0.4,9],[9,10]],size=int(1e4))

print(points)
[[-2.50584156 2.77190372]
[ 2.68192136 -3.83203819]
...,
[-1.10738221 -1.72058301]
[ 3.75168017 5.6905342 ]]

print(type(points))
<class 'numpy.ndarray'>

data = ascii.read(datafile)
type(data['ra'])
astropy.table.column.Column
type(data['dec'])
astropy.table.column.Column

然后我尝试:

points = np.array([data['ra']], [data['dec']])

并得到一个

TypeError: data type not understood

想法?

最佳答案

可以使用 data 属性将 astropy Table Column 对象转换为 numpy 数组:

In [7]: c = Column([1, 2, 3])

In [8]: c.data
Out[8]: array([1, 2, 3])

您还可以使用 as_array() Table 方法将整个表转换为 numpy 结构化数组(例如示例中的 data.as_array())。

顺便说一句,我认为实际的问题不是关于 astropy Column 而是你的 numpy 数组创建语句。大概应该是:

arr = np.array([data['ra'], data['dec']])

这适用于Column对象。

关于python - 将 astropy.table.columns 转换为 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46298554/

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