【问题标题】:Dot product Matrices点积矩阵
【发布时间】:2013-03-29 02:21:56
【问题描述】:

嘿,我只是想知道如何使用用户定义的函数计算两个矩阵的点积。

例如:

row(C,0)=[4, 1, 9]
col(D,0)=[2, 5, 1]
def dotProduct(x,y):


print(dotProduct(row(C,0), col(D,0)))

应该是 22

【问题讨论】:

    标签: matrix python-3.x dot-product


    【解决方案1】:
    def dotProduct(x,y):
        prod=0
        for i in range(len(x)):
            prod=prod+x[i]*y[i]
        return prod
    

    【讨论】:

    • sum(xi * yi for xi, yi in zip(x, y))
    猜你喜欢
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多