Re: [Numpy-discussion] how to name "contagious" keyword in np.ma.convolve

2016-10-16 Thread Hanno Klemm


> On 16 Oct 2016, at 03:21, Allan Haldane  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]
> 
> Allan
> 

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. 

Hanno



___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] add elementwise addition & subtraction to einsum

2016-10-16 Thread Matthew Harrigan
Hello,

This is a follow on for issue 8139
.  I propose adding elementwise
addition and subtraction functionality to einsum.  I love einsum as it
clearly and concisely defines complex linear algebra.  However elementwise
addition is a very common linear algebra operation and einsum does not
currently support it.  The Einstein field equations
,
what the notation was originally developed to document, contain that
functionality.  It is fairly common in stress analysis (my background), for
example see these lectures notes

.

Specifically I propose adding "+" and "-" characters which separate current
einsum statements which are then combined elementwise.  An example is A =
np.einsum('ij,jk+ij,jk', B, C, D, E), which is A = B * C + D * E.  I wrote
a crude function

to demonstrate the functionality.

I believe the functionality is useful, in keeping with the spirit of a
clean concise API, and doesn't break the existing API, which could warrant
acceptance.

Additionally I believe it opens the possibility of many interesting
performance optimizations.  For instance, many of the optimizations in this
NEP 
could be done internally to the einsum function, which may be easier to
accomplish given the narrower scope (but I am ignorant of all the low level
C internals of numpy).  The example in the beginning could become A =
np.einsum('...+...+...', B, C, D).

Thank you for your time and consideration.
Matt
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion