我正在尝试使用astropy.cosmology。正如文档所说,当我使用Hubble参数方法时,它应该给我一个单位的值 - astropy.cosmology documentation
但它给了我一个数字,可以在这里看到 -
ohm@ohm-ThinkCentre-M57:~/projects/mucalc$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from astropy import cosmology
>>> cosmology.core.set_current(cosmology.Planck13)
>>> H0 = cosmology.H(10**6)
>>> print H0
647883886243.0
>>> H0.value
ERROR: AttributeError: 'numpy.float64' object has no attribute 'value' [unknown]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.float64' object has no attribute 'value'
>>>
可能是什么问题?
答案 0 :(得分:6)
在Astropy 0.3中添加了对数量的支持(参见here),所以你看到的是Astropy 0.2.x的预期行为。这是0.3:
的输出In [1]: from astropy import cosmology
In [2]: cosmology.core.set_current(cosmology.Planck13)
In [3]: H0 = cosmology.H(10**6)
In [4]: print H0
6.47883897961e+11 km / (Mpc s)
请注意,您也可以这样做:
In [8]: from astropy.cosmology import Planck13
In [9]: print Planck13.H(10**6)
6.47883897961e+11 km / (Mpc s)
更简洁。