天体笛卡尔表示到 NumPy 数组

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

我有一个 Astropy CartesianRepresentation 对象,如下所示:

<CartesianRepresentation (x, y, z) in km
    [(  4082.71516205,   248.89483863, -5882.92418597),
     (  5501.55728501,  2581.64039883, -5017.87534951), ...

我想将其转换为 NumPy ndarray,以便可以对各个元素进行索引。有办法做到这一点吗?

python numpy-ndarray astropy
2个回答
3
投票

考虑到您的对象名称是“r”,您可以访问 x 组件的 r.x 以及其他组件的 r.y 和 r.z 。您还可以检索 r.xyz。


0
投票

假设

cart
CartesianRepresentation
:

# both of these work
cartesian_ndarray = cart.xyz.value
cartesian_ndarray = np.array(cart.xyz.value)

有关文档,请参阅 CartesianRepresentation 类的 xyz 属性及其类型 Quantity,其基础是 numpy 数组。

如果

cart_diff
CartesianDifferential
:

# both of these work
cartesian_ndarray = cart_diff.d_xyz.value
cartesian_ndarray = np.array(cart_diff.d_xyz.value)

有关文档,请参阅 CartesianDifferential 类的 d_xyz 属性及其类型 Quantity,其基础是 numpy 数组。

© www.soinside.com 2019 - 2024. All rights reserved.