克罗内克张量积Python实现

def kron(arr1, arr2):
    list2 = []
    for i in arr2:
        for ii in arr1:
            list1 = []
            for j in i:
                for jj in ii:
                    list1.append(j * jj)
            list2.append(list1)
    return list2


if __name__ == "__main__":
    arr1 = [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]
    arr2 = [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]
    print(kron(arr1, arr2))
最后修改:2021 年 11 月 18 日
如果觉得我的文章对你有用,请随意赞赏