[AstroPy] Trouble when creating a vectorial Quantity from its components
Juan Luis Cano
juanlu001 at gmail.com
Sat Dec 28 04:32:16 EST 2013
Hello all, I'm using astropy 0.3 under python 3.3 with numpy 1.8.0, and
while I was trying to build a vector `Quantity` from its components I
found this:
```
>>> import numpy as np
>>> from astropy import units as u
>>> p = 1000 * u.km; p
<Quantity 1000 km>
>>> nu = 28 * u.deg
>>> r = [p * np.cos(nu), p * np.sin(nu), 0]; r
[<Quantity 882.947592858927 km>, <Quantity 469.4715627858908 km>, 0]
```
This is perfectly normal, but I expected a vectorial `Quantity`. Trying
to convert to an array didn't work:
```
>>> np.array(r)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.
```
Is there any way I can avoid doing this?
```
>>> r = [p.si.value * np.cos(nu), p.si.value * np.sin(nu), 0] *
p.si.unit; r
<Quantity [ 882947.59285893, 469471.56278589, 0. ] m>
```
because it might get quite verbose if there are more magnitudes.
Thanks!
More information about the AstroPy
mailing list