Hello, This is a follow on for issue 8139 <https://github.com/numpy/numpy/issues/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 <https://en.wikipedia.org/wiki/Einstein_field_equations#Mathematical_form>, 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 <http://www.brown.edu/Departments/Engineering/Courses/En221/Notes/Index_notation/Index_notation.htm> .

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 <https://github.com/mattharrigan/numpy/blob/einsum-elementwise/numpy/core/einsum_extension.py> 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 <http://docs.scipy.org/doc/numpy/neps/deferred-ufunc-evaluation.html> 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