[Numpy-discussion] take not respecting masked arrays?
pete at shinners.org
Mon Mar 1 23:36:08 EST 2010
On 02/28/2010 10:58 PM, Pierre GM wrote:
> On Mar 1, 2010, at 1:02 AM, Peter Shinners wrote:
>>> Here is the code as I would like it to work.
>> import numpy as np
>> values = np.array((40, 18, 37, 9, 22))
>> index = np.arange(3)[None,:] + np.arange(5)[:,None]
>> mask = index>= len(values)
>> maskedindex = np.ma.array(index, mask=mask)
>> lookup = np.ma.take(values, maskedindex)
>> # This fails with an index error, but illegal indices are masked.
> OK, but this doesn't even work on a regular ndarray: np.take(values, index) raises an IndexError as well. Not much I can do there, then.
>> # It succeeds when mode="clip", but it does not return a masked array.
>> print lookup
> Oh, I get it... The problem is that we use `take` on a ndarray (values) with a masked array as indices (maskedindex). OK, I could modify some of the mechanics so that a masked array is output even if a ndarray was parsed.
> Now, about masked indices: OK, you're right, the result should be masked accordingly. Can you open a ticket, then ?
Excellent. Ticket is #1418
More information about the NumPy-Discussion