Python Forum
reshaping numpy array ValueError: total size of new array must be unchanged - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: reshaping numpy array ValueError: total size of new array must be unchanged (/thread-4003.html)



reshaping numpy array ValueError: total size of new array must be unchanged - metalray - Jul-15-2017

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.