Python Forum

Full Version: reshaping numpy array ValueError: total size of new array must be unchanged
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear Python experts,

I am trying to reshape my numpy array "des" to shape 4,100 but every
time I get the "ValueError: total size of new array must be unchanged"
error.
Why is that?

def big():
    from sklearn.linear_model import LinearRegression
    from sklearn.preprocessing import PolynomialFeatures
  
    pred_data = np.linspace(0,10,100)
    degree = [1,3,6,9]

    for i in range(len(degree)):
        pred_data = np.linspace(0,10,100)
        pred_data = np.array(pred_data).reshape(-1,1)
        poly = PolynomialFeatures(degree=degree[i])    

        #since the assignment says to use the X_train data)
        X_F1_poly = poly.fit_transform(X_train[:,np.newaxis])

        pred_data = poly.fit_transform(pred_data)
        linreg = LinearRegression().fit(X_F1_poly, y_train)

        pred = linreg.predict(pred_data)
        des = np.array(pred,np.float32).reshape(4, 100)
        #print(X_F1_poly.shape)
    return pred
big()
Would be super thankful for any help.