How do you prepare a floating accumulator aligned to the input?

zeros_like initializes every slot to zero in the template's shape. The output type can be chosen independently.

numpy.zeros_like in practice

Fractional corrections to two rows of integer observations need a 2×2 floating buffer. Deriving the shape from the observations also picks up a changed batch size.

import numpy as np
np.zeros_like([[1,2],[3,4]], dtype=float)

Result [[0.0, 0.0], [0.0, 0.0]]

中文

怎样给每个输入特征准备浮点累计器?

zeros_like 复制模板的形状并把元素置零。可单独指定输出类型。

numpy.zeros_like 算例

两行整数观测需要累计小数修正量,可以保留 2×2 形状并改用浮点。若以后新增样本维度,模板会自动带上该维。

import numpy as np
np.zeros_like([[1,2],[3,4]], dtype=float)

结果 [[0.0, 0.0], [0.0, 0.0]]

References / 参考来源

Keep reading / 继续阅读