[AstroPy] numpy.arange and quantities
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:
(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.
> On 29 Nov 2016, at 10:19, Leonard Burtscher <burtscher at strw.leidenuniv.nl> wrote:
> OK, I see. Have you seen the discussion here?
> 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:
>> 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.
>> AstroPy mailing list
>> AstroPy at scipy.org
> AstroPy mailing list
> AstroPy at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the AstroPy