可能有时我们会遇到这样的问题,程序要求(n,)维,但你给的是(n,1)维,
用 numpy.squeeze:
>>> x = np.array([[[0], [1], [2]]]) >>> x.shape (1, 3, 1) >>> np.squeeze(x).shape (3,) >>> np.squeeze(x, axis=(2,)).shape (1, 3)

可能有时我们会遇到这样的问题,程序要求(n,)维,但你给的是(n,1)维,
用 numpy.squeeze:
>>> x = np.array([[[0], [1], [2]]]) >>> x.shape (1, 3, 1) >>> np.squeeze(x).shape (3,) >>> np.squeeze(x, axis=(2,)).shape (1, 3)