How do you join batches with different sample counts?

concatenate joins arrays along an existing dimension. All dimensions outside the join axis must agree.

numpy.concatenate in practice

Joining one training row to two more leaves the same two features. A swapped column order passes the shape check, so compare feature names as well.

import numpy as np
np.concatenate(([[1,2]],[[3,4],[5,6]]), axis=0)

Result [[1, 2], [3, 4], [5, 6]]

中文

两个大小不同的批次怎样合并为一批?

concatenate 沿已有轴拼接数组,除拼接轴外的形状必须一致。

numpy.concatenate 算例

合并一行和两行训练记录后仍是两列特征。若两批交换过列顺序,形状检查会通过,仍需按特征名校对。

import numpy as np
np.concatenate(([[1,2]],[[3,4],[5,6]]), axis=0)

结果 [[1, 2], [3, 4], [5, 6]]

References / 参考来源

Keep reading / 继续阅读