# [Numpy-discussion] einsum

Mark Wiebe mwwiebe at gmail.com
Wed Jan 26 18:29:28 EST 2011

```On Wed, Jan 26, 2011 at 3:18 PM, Hanno Klemm <klemm at phys.ethz.ch> wrote:

>
> Mark,
>
> interesting idea. Given the fact that in 2-d euclidean metric, the
> Einstein summation conventions are only a way to write out
> conventional matrix multiplications, do you consider at some point to
> include a non-euclidean metric in this thing? (As you have in special
> relativity, for example)
>
> Something along the lines:
>
> eta = np.diag(-1,1,1,1)
>
> a = np.array(1,2,3,4)
> b = np.array(1,1,1,1)
>
> such that
>
> einsum('i,i', a,b, metric=eta) = -1 + 2 + 3 + 4
>

This particular example is already doable as follows:

>>> eta = np.diag([-1,1,1,1])
>>> eta
array([[-1,  0,  0,  0],
[ 0,  1,  0,  0],
[ 0,  0,  1,  0],
[ 0,  0,  0,  1]])
>>> a = np.array([1,2,3,4])
>>> b = np.array([1,1,1,1])
>>> np.einsum('i,j,ij', a, b, eta)
8

I think that's right, did I understand you correctly?

Cheers,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110126/64580ceb/attachment.html>
```

More information about the NumPy-Discussion mailing list