How does reflection padding extend a sequence at its boundaries?

Reflection mode in pad mirrors interior values beyond each boundary, ordinarily without duplicating the endpoint immediately beside itself.

numpy.pad in practice

Padding [1,2,3] by one on each side gives [2,1,2,3,2]. Reflection assumes a boundary behavior. Choose another convention if the physical signal stops at the edge.

import numpy as np
np.pad([1,2,3],1,mode='reflect')

Result [2, 1, 2, 3, 2]

中文

反射填充怎样为序列边缘构造邻域?

pad 的 reflect 模式把边界内侧的值镜像到外侧,通常不会在紧邻位置重复端点本身。

numpy.pad 算例

序列 [1,2,3] 两端各补一格得到 [2,1,2,3,2]。镜像是假设的边界行为,若实际信号在端点截断,应另选填充约定。

import numpy as np
np.pad([1,2,3],1,mode='reflect')

结果 [2, 1, 2, 3, 2]

References / 参考来源

Keep reading / 继续阅读