[Numpy-discussion] how to name "contagious" keyword in np.ma.convolve
klemm at phys.ethz.ch
Sun Oct 16 05:52:57 EDT 2016
> On 16 Oct 2016, at 03:21, Allan Haldane <allanhaldane at gmail.com> wrote:
>> On 10/14/2016 07:49 PM, Juan Nunez-Iglesias wrote:
>> +1 for propagate_mask. That is the only proposal that immediately makes
>> sense to me. "contagious" may be cute but I think approximately 0% of
>> users would guess its purpose on first use.
>> Can you elaborate on what happens with the masks exactly? I didn't quite
>> get why propagate_mask=False was unintuitive. My expectation is that any
>> mask present in the input will not be set in the output, but the mask
>> will be "respected" by the function.
> Here's an illustration of how the PR currently works with convolve, using the name "propagate_mask":
> >>> m = np.ma.masked
> >>> a = np.ma.array([1,1,1,m,1,1,1,m,m,m,1,1,1])
> >>> b = np.ma.array([1,1,1])
> >>> print np.ma.convolve(a, b, propagate_mask=True)
> [1 2 3 -- -- -- 3 -- -- -- -- -- 3 2 1]
> >>> print np.ma.convolve(a, b, propagate_mask=False)
> [1 2 3 2 2 2 3 2 1 -- 1 2 3 2 1]
Given this behaviour, I'm actually more concerned about the logic ma.convolve uses in the propagate_mask=False case. It appears that the masked values are essentially replaced by zero. Is my interpretation correct and if so does this make sense?
When I have similar situations, I usually interpolate between the valid values. I assume there are a lot of use cases for convolutions but I have difficulties imagining that ignoring a missing value and, for the purpose of the computation, treating it as zero is useful in many of them.
More information about the NumPy-Discussion