将行从星形表转换为numpy数组

问题描述 投票:1回答:2

我有一个数字表

<Table length=3>
  a     b  
int64 int64
----- -----
    1     3
    2     5
    4     7

而且我想将一行转换为numpy数组。但是,当我尝试时,最终得到的数组没有维度

In: np.array(mytable[0]).shape
Out: ()

如果可以的话

myrow = mytable[0]
myrow[0]

我收到错误

IndexError: too many indices for array

[我是否可以执行类似t[0].values的操作,返回array([1, 3])

python arrays numpy astropy
2个回答
1
投票

>>> np.lib.recfunctions.structured_to_unstructured(np.array(t[0])) array([1, 3]) >>> np.lib.recfunctions.structured_to_unstructured(np.array(t[1:])) array([[2, 5], [4, 7]])


0
投票
>>> np.array(list(t[0])) array([1, 3])
© www.soinside.com 2019 - 2024. All rights reserved.