当前位置:嗨网首页>书籍在线阅读

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))