结合Einsum表达式 [英] Combine Einsum Expressions

查看:77
本文介绍了结合Einsum表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想评估

E = np.einsum('ij,jk,kl->ijkl',A,A,A)
F = np.einsum('ijki->ijk',E)

其中A是矩阵(大小不超过1000 x 1000).计算E速度很慢.我想通过仅计算存储在F中的对角线"元素来加快此速度.是否可以将这两个表达式组合使用?/是否有更好的方法来加快此计算速度?

where A is a matrix (no more than 1000 by 1000 in size). Computing E is slow. I would like to speed this up by only computing the "diagonal" elements which I store in F. Is it possible to combine these two expressions?/Are there any better ways to speed up this computation?

推荐答案

我不确定是否有自动方法,但是您始终可以自己做数学运算并为einsum给出最终表达式:

I'm not sure if there is an automatic way, but you can always do the maths yourself and give einsum the final expression:

F = np.einsum('ij,jk,ki->ijk', A, A, A)

这篇关于结合Einsum表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆