09-点积
7.3.1 点积
大家都还记得,前馈阶段和反向传播阶段都需要用到点积。幸运的是,用Python内置函数 zip() 和 sum() 很容易就能实现点积。先把函数保存在util.py文件中。具体代码如代码清单7-1所示。
代码清单7-1 util.py
from typing import List
from math import exp
# dot product of two vectors
def dot_product(xs: List[float], ys: List[float]) -> float:
return sum(x * y for x, y in zip(xs, ys))