[Numpy-discussion] einsum
Hanno Klemm
klemm at phys.ethz.ch
Wed Jan 26 18:48:44 EST 2011
Am 27.01.2011 um 00:29 schrieb Mark Wiebe:
> 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
Yes, that's what I had in mind. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110127/f2a50c42/attachment.html>
More information about the NumPy-Discussion
mailing list