I need to access the float value from the Distance astropy class .
Here's the MWE:
from astropy.coordinates import Distance
from astropy import units as u
d = []
for _ in range(10):
d.append(Distance(_, unit=u.kpc))
This leads to a list of objects <class 'astropy.coordinates.distances.Distance'>:
[<Distance 0.0 kpc>, <Distance 1.0 kpc>, <Distance 2.0 kpc>, <Distance 3.0 kpc>, <Distance 4.0 kpc>, <Distance 5.0 kpc>, <Distance 6.0 kpc>, <Distance 7.0 kpc>, <Distance 8.0 kpc>, <Distance 9.0 kpc>]
I need to store floats (not objects), and I don't know how to get them. Since this MWE is part of a larger code, I cannot just do it d.append(_). I need to access floats from objects generated by a class Distance.
Add
I tried converting the list to a numpy array using
np.asarray(d)
but I get:
ValueError: setting an array element with a sequence.
source
share