python-quantities-developers team mailing list archive
-
python-quantities-developers team
-
Mailing list archive
-
Message #00016
Re: concerns about zeros
On Tue, Jan 6, 2009 at 3:51 AM, John Salvatier <jsalvati@xxxxxxxxxxxxxxxx>wrote:
> I was implementing Quantities.fill(scalar) and it made me think about
> assigning zeros to Quantity array elements.
> If a quantity is non-dimensionless and someone tries to assign zero to an
> array element, an error will be thrown, even if it makes sense to assign a
> zero to the element.
>
> Example:
>
> x = [10, 5, 1, 3] * BTU
>
> x[1] = 0 # this will throw an error because a float does not have units
> of BTU
>
> I worry about this because I imagine that a good deal of algorithms that we
> would like to work with Quantities assign zeros to some array elements in
> some circumstances, and that will break compatibility. I'm not really sure
> how to deal with that.
>
> What do you think?
>
I think Quantities should not blur the distinction between a physical
quantity, which has both magnitude and dimensionality, and the magnitude
itself. If you want to modify the magnitude without worrying about the
units, the mechanism exists to do so:
x.magnitude[1]=0
References