← Back to team overview

python-quantities-developers team mailing list archive

[Question #105142]: Is there any way to use quantities with numpy structured arrays?

 

New question #105142 on python-quantities:
https://answers.launchpad.net/python-quantities/+question/105142

I'm thinking about using quantities with a meteorological analysis packge I've been cobbling together.  So far, since I've been focusing on reading text data, I've been using structured arrays as the main data structure to pass all the different fields around. I have a few questions about using quantities in this way:

Is there any way to use Quantities to assign a different unit to each field of the structured array?

Has this use case even been considered?

If I just try to make a quantity array from a structured array, I can get a single unit assigned to all of the fields, but then I can't convert it:

In [23]: bq.units = pq.foot
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/rmay/radar_sim/data/<ipython console> in <module>()

/home/rmay/.local/lib/python2.6/site-packages/quantities/quantity.pyc in _set_units(self, units)
    170             )
    171         mag = self.magnitude
--> 172         mag *= cf
    173         self._dimensionality = to_u.dimensionality
    174     units = property(_get_units, _set_units)

TypeError: unsupported operand type(s) for *=: 'numpy.ndarray' and 'numpy.float64'

This is likely due to the fact that structured arrays generally don't support arithmetic operations.

Am I just trying to stuff too much into the numpy array and instead should just look at a Bunch-like object?

-- 
You received this question notification because you are a member of
Python Quantities Development Team, which is an answer contact for
python-quantities.