Compute dot product of two vectors without using extra libraries

后端 未结 1 1819
星月不相逢
星月不相逢 2021-01-29 11:24

I would like to write a function to compute the dot product of two vectors without using extra libraries. Following is an attempt that I made. Can someone point out the flaws in

1条回答
  •  生来不讨喜
    2021-01-29 12:15

    def dot(v1,v2):
        if len(v1) != len(v2):
            raise ValueError
        return sum(i1*i2 for i1,i2 in zip(v1,v2))
    

    0 讨论(0)
提交回复
热议问题