忽然笑
该reshape()方法可以直接调用numpy.array,即:Y = np.random.rand(3, 4)Y.reshape((Y.shape[0], Y.shape[1], 1))输出:array([[[0.03398233], [0.31845358], [0.26508794], [0.4154345 ]], [[0.80924495], [0.86116906], [0.24186532], [0.64169452]], [[0.61352962], [0.95214732], [0.26994666], [0.99091755]]])如果你的Y数组是一维的,你仍然可以像这样把它变成 3D:Y.reshape((1, 1, -1))输出:array([[[0.52130672]], [[0.25807463]], [[0.81201524]], [[0.08846268]], [[0.20831986]], [[0.823997 ]], [[0.483052 ]], [[0.15120415]], [[0.19601734]], [[0.55933897]], [[0.9112403 ]], [[0.1048653 ]]])