[Numpy-discussion] mapping a function to a masked array

Ben Elliston bje at air.net.au
Wed Jan 12 06:45:54 EST 2011


I have a masked array of values that I would like to transform through
a user-defined function.  Naturally, I want to ignore any values that
are masked in the initial array.

The user-defined function examines other points around the value in
question, so I need to use ndenumerate (or similar) to get the array
index as I iterate over the array.

So, I have two questions: how to make this run without looping in
Python, and how to avoid masked values.  Here is the clunky solution I
have so far:

    result = ma.copy (data)
    for i, val in ndenumerate (data):
        if not data.mask[i]:
	    result[i] = myfunc (data, i, val)

Any suggestions?

Thanks, Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110112/f2507c00/attachment.sig>


More information about the NumPy-Discussion mailing list