将astropy.table.columns转换为numpy数组 [英] Converting astropy.table.columns to a numpy array

查看:226
本文介绍了将astropy.table.columns转换为numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制points:

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

有想法吗?

推荐答案

numpy.array的签名为

The signature of numpy.array is numpy.array(object, dtype=None,)

因此,在调用np.array([data['ra']], [data['dec']])时,[data['ra']]是要转换为numpy数组的对象,而[data['dec']]是无法理解的数据类型(如错误所示).

Hence, when calling np.array([data['ra']], [data['dec']]), [data['ra']] is the object to convert to a numpy array, and [data['dec']] is the data type, which is not understood (as the error says).

从问题中实际上并不清楚您要实现的目标-可能类似

It's not actually clear from the question what you are trying to achieve instead - possibly something like

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

这篇关于将astropy.table.columns转换为numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆