[AstroPy] numpy.arange and quantities

Christoph Deil deil.christoph at googlemail.com
Tue Nov 29 04:26:01 EST 2016


Hi Ole, Leo,

There’s also a mention of known issues with some numpy functions with Quantity objects here:
http://astropy.readthedocs.io/en/latest/known_issues.html#quantity-issues <http://astropy.readthedocs.io/en/latest/known_issues.html#quantity-issues>
(arange isn’t mentioned specifically).

The workaround is just to do something like this, i.e. call the function with the value array and after put the unit back on:

q_in = <some quantity>
unit = <some fixed unit>
a_out  = np.somefunction(a_in.to(unit).value)
q_out = Quantity(a_out, unit)

I don’t know if the Numpy / Quantity situation will get better over the years, or if it will mostly stay as-is due do backward-compatibility constraints in Numpy.

Christoph

> On 29 Nov 2016, at 10:19, Leonard Burtscher <burtscher at strw.leidenuniv.nl> wrote:
> 
> OK, I see. Have you seen the discussion here?
> https://github.com/astropy/astropy/wiki/Quantity-Arrays
> 
> Seems to be a known problem, but I'm don't know if it has been solved.
> 
> 
>> Am 29.11.2016 um 10:16 schrieb Ole Streicher <astropy at liska.ath.cx>:
>> 
>> Leonard Burtscher <burtscher at strw.leidenuniv.nl> writes:
>>> r=np.arange(0,9,0.1)*u.km
>>> 
>>> works.
>> 
>> Sure. But the quantities are already given. I could convert them to
>> numbers first (with a random unit), like
>> 
>> np.arange(z0/u.m, z1/u.m, dz/u.m) * u.m
>> 
>> But this looks really ugly.
>> 
>> Cheers
>> 
>> Ole
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
> 
> --
> http://strw.leidenuniv.nl/~burtscher
> 
> 
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20161129/3211da3d/attachment.html>


More information about the AstroPy mailing list