[PYTHON MATRIX-SIG] handling missing data values in NumPy

Jim Hugunin hugunin@mit.edu
Mon, 2 Jun 1997 13:18:35 -0400

> I often deal with time sequences of 2D arrays that have
> some values missing at random times. I want to obtain
> an average of these sequences along the time axis
> taking into account the missing values.

I can tell you how I solve the problem in my own code.  No guarantees that this is
appropriate for you though...

>>> from Numeric import *
>>> data  = array([1,2,666,4,5])
>>> valid = array([1,1,  0,1,1])
>>> print sum(data*valid)/sum(valid)

If you do a lot of this sort of thing, you could encapsulate this way of
representing arrays with missing values into a new python object, but that's
possibly overkill.


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org