📅  最后修改于: 2022-03-11 14:45:42.692000             🧑  作者: Mango
a = np.array([[1, 2], [1, 2]])
# indexing with np.newaxis inserts a new 3rd dimension,
# which we then repeat the array along
b = np.repeat(a[:, :, np.newaxis], 3, axis=2)
print(b.shape)
# (2, 2, 3)