einsum

版本 1.0.1 (2.3 KB) 作者: Yohai
Efficiently calculates tensor contraction in any dimension. It uses MATLAB's matrix multiplication so it's parallelized and optimized.
707.0 次下载
更新时间 2018/11/13

查看许可证

Usage: einsum(A,B,s)
einsum(A,B,iA,iB)

Calculates the contraction of A and B which are n-dimensional tensors.
The contraction is specified either by s, in Einstein notation, or by two
vectors, iA and iB which list the indices to contract on for each tensor.

Example:
A=rand(7,4,5);
B=rand(5,7);
To contract the 1st dimension of A with the 2nd dimension of B, use
einsum(A, B, 'ijk,li->jkl') OR einsum(A, B, 1, 2)
The result will be of size [4,5,5].

To contract the 3rd dimension of A with the 1st dimension of B, use
einsum(A, B, 'ijk,kl->ijl') OR einsum(A, B, 3, 1)
The result will be of size [7,4,7].

To do both contractions at once, use
einsum(A,B,'ijk,ki->j') OR einsum(A, B, [1 3], [2 1])

Using the iA, iB it is not possible to specify the order of dimensions
in the output, they're just in the same order as the input, with the
contracted dimensions omitted.

Author: Yohai Bar-Sinai

引用格式

Yohai (2024). einsum (https://www.mathworks.com/matlabcentral/fileexchange/68995-einsum), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2018b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.1

typos

1.0.0