tensor.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:tncontract 作者: andrewdarmawan 项目源码 文件源码
def contract_internal(self, label1, label2, index1=0, index2=0):
        """By default will contract the first index with label1 with the 
        first index with label2. index1 and index2 can be specified to contract
        indices that are not the first with the specified label."""

        label1_indices = [i for i, x in enumerate(self.labels) if x == label1]
        label2_indices = [i for i, x in enumerate(self.labels) if x == label2]

        index_to_contract1 = label1_indices[index1]
        index_to_contract2 = label2_indices[index2]

        self.data = np.trace(self.data, axis1=index_to_contract1, axis2=
        index_to_contract2)

        # The following removes the contracted indices from the list of labels
        self.labels = [label for j, label in enumerate(self.labels)
                       if j not in [index_to_contract1, index_to_contract2]]

    # aliases for contract_internal
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号