mindchemistry.e3.utils.Ncon
- class mindchemistry.e3.utils.Ncon(con_list)[源代码]
多个张量的缩并运算符,功能类似于 Einsum。
- 参数:
con_list (List[List[int]]) - 每个张量的索引列表。每个列表中的数目应与相应张量的维度相对应。正索引表示要缩并或求和的维度。负索引表示要保留的维度(作为批维度)。
- 输入:
input (List[Tensor]) - 张量列表。
- 输出:
output (Tensor) - 结果张量,形状取决于输入和运算过程。
- 异常:
ValueError: 如果命令的数量与操作的数量不匹配。
- 支持平台:
Ascend
样例:
>>> from mindspore import ops >>> from mindchemistry.e3.utils import Ncon Trace of a matrix: >>> a = ops.ones((3, 3)) >>> Ncon([[1, 1]])([a]) 3.0 Diagonal of a matrix: >>> Ncon([[-1, -1]])([a]) [1. 1. 1.] Outer product: >>> b = ops.ones((2)) >>> c = ops.ones((3)) >>> Ncon([[-1], [-2]])([b, c]).shape (2, 3) Batch matrix multiplication >>> d = ops.ones((2, 3, 4)) >>> e = ops.ones((2, 4, 1)) >>> Ncon([[-1, -2, 1], [-1, 1, -3]])([d, e]).shape (2, 3, 1)