def dotproduct(x, y):
"""dotproduct(x, y) -> int
Computes the dot product of `x` and `y`.
Arguments:
x(iterable): An iterable.
x(iterable): An iterable.
Returns:
The dot product of `x` and `y`, i.e.: ``x[0] * y[0] + x[1] * y[1] + ...``.
Example:
>>> dotproduct([1, 2, 3], [4, 5, 6])
... # 1 * 4 + 2 * 5 + 3 * 6 == 32
32
"""
return sum(imap(operator.mul, x, y))
评论列表
文章目录