8000 Broadcasting quantities · Issue #7832 · astropy/astropy · GitHub
[go: up one dir, main page]

Skip to content
Broadcasting quantities #7832
@drdavella

Description

@drdavella

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0