【发布时间】:2020-01-26 05:29:36
【问题描述】:
采用一个 3 维数组。从结束位置填充实例,如下例所示。也就是说,我需要填充沿数组边缘值镜像的话语的反射。
数组a:
array ([array([[3, 1, 4, 1],
[5, 9, 2, 6],
[5, 3, 5, 8]]),
array([[9, 7, 9, 3],
[2, 3, 8, 4]]),
array([[6, 2, 6, 4],
[3, 3, 8, 3],
[2, 7, 9, 5],
[0, 2, 8, 8]])], dtype=object)
dim1 = a.shape[0] # n
dim2 = max([i.shape[0] for i in a]) # m
dim3 = a[0].shape[1] # k
填充后最终矩阵的维度:
结果 = np.zeros((dim1, dim2, dim3))
输出:
[[[3. 1. 4. 1.]
[5. 9. 2. 6.]
[5. 3. 5. 8.]
[5. 3. 5. 8.]]
[[9. 7. 9. 3.]
[2. 3. 8. 4.]
[2. 3. 8. 4.]
[9. 7. 9. 3.]]
[[6. 2. 6. 4.]
[3. 3. 8. 3.]
[2. 7. 9. 5.]
[0. 2. 8. 8.]]]
如何使用 numpy.pad 获得输出?
【问题讨论】: