<p>我需要从<a href="http://docs.astropy.org/en/v0.2.1/_generated/astropy.coordinates.distances.Distance.html" rel="nofollow">Distance</a>astropy类访问float值。在</p>
<p>这里有一个MWE:</p>
<pre><code>from astropy.coordinates import Distance
from astropy import units as u
d = []
for _ in range(10):
d.append(Distance(_, unit=u.kpc))
</code></pre>
<p>这将产生<code><class 'astropy.coordinates.distances.Distance'></code>对象的列表:</p>
^{pr2}$
<p>我需要存储<em>浮动</em>(而不是对象),但我不知道如何访问它们。因为这个MWE是一个更大代码的一部分,我不能只做<code>d.append(_)</code>。我需要从<code>Distance</code>类生成的对象访问float。在</p>
<p>添加:</p>
<p>我尝试将列表转换为numpy数组:</p>
<pre><code>np.asarray(d)
</code></pre>
<p>但我得到:</p>
<pre><code>ValueError: setting an array element with a sequence.
</code></pre>