-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
Currently, when broadcasting a Quantity
, the result is a bare ndarray
. Consider the following basic example:
>>> import numpy as np
>>> from astropy import units as u
>>> q = [x for x in range(10)] * u.AA
>>> q
<Quantity [0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] Angstrom>
>>> np.broadcast_to(q, (4, 10))
array([[0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
[0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
[0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
[0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]])
This isn't a huge deal, because I could have just done the following:
>>> np.broadcast_to(q, (4, 10)) * q.unit
But it's annoying and redundant. It would be nice if Quantity
handled this automatically. I'm not sure whether there's some kind of magic method we can add to Quantity
to handle this properly? Otherwise maybe something like astropy.units.quantity.broadcast_to
?