2

谁能解释我为什么会收到以下错误:

ValueError: non-broadcastable output operand with shape (1,1) 
doesn't match the broadcast shape (1,2)

执行时:

    X = np.array([[i, j] for i, j in zip(dati['a'], dati['b'])], 
        dtype = float) #np.shape(X) is (23, 2)

    scaler = MinMaxScaler(feature_range=(0, 1))
    X = scaler.fit_transform(X) #np.shape(X) is (23, 2)

    X = np.reshape(X, (X.shape[0], X.shape[1], 1)) #np.shape(X) is (23, 2, 1)

    X = f(X) #np.shape(X) is (23, 1)

    X = scaler.inverse_transform(X)

    p = np.array([dati[['a','b']].iloc[-1]], dtype = float) #np.shape(X) is (1, 2)

    scaler = MinMaxScaler(feature_range=(0, 1))
    p = scaler.fit_transform(p) #np.shape(X) is (1, 2)

    p = np.reshape(p, (p.shape[0], p.shape[1], 1)) #np.shape(X) is (1, 2, 1)

    p = f(p) #np.shape(p) is (1, 1)

    p = scaler.inverse_transform(p) #Here the error

我真的不明白为什么对尺寸与 X 不同的 f(X) 的结果应用 inverse_transform 一切都很好,而在尺寸与 p 不同的 f(p) 上做同样的事情时,我得到了错误。

4

0 回答 0