题解 | #矩阵乘法#

矩阵乘法

http://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b

乘法就是数组或者二维列表倒置相乘
while True:
    try:
        l1 = int(input())
        l2 = int(input())
        l3 = int(input())

        list1 = []
        list2 = [[] for i in range(l3)]

        for i in range(l1):
            list1.append(list(map(int, input().split())))

        for i in range(l2):
            res = list(map(int, input().split()))
            for n, x in enumerate(res):
                list2[n].append(x)

        res_list = []
        for x, i in enumerate(list1):

            list3 = []
            for p in range(l3):
                n = 0
                for y, j in enumerate(i):
                    n += j * list2[p][y]
                list3.append(n)
            res_list.append(list3)
        # print(list1, list2)
        for i in res_list:
            print(' '.join(list(map(str, i))))
    except EOFError:
        break

全部评论

相关推荐

迷茫的大四🐶:都收获五个了,兄弟那还说啥,不用改了,去玩吧
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 11:29
已编辑
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务