Python Forum
reshaping numpy array ValueError: total size of new array must be unchanged
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reshaping numpy array ValueError: total size of new array must be unchanged
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie here. Create an array from file data? Rayj00 2 1,199 Jan-13-2023, 01:35 PM
Last Post: perfringo
  random interger array question rpang 3 1,781 Nov-05-2022, 12:31 PM
Last Post: deanhystad
  2-D array imrobinotmar 0 1,155 Jul-11-2022, 01:11 PM
Last Post: imrobinotmar
  Array Indices? DaveG 1 1,221 Mar-20-2022, 05:57 AM
Last Post: deanhystad
  an array to count votes thechungusmaximus 2 1,463 Mar-09-2022, 03:44 PM
Last Post: DeaD_EyE
  How to multiply tuple values in array? EngiPorem 3 2,953 Aug-27-2021, 03:26 AM
Last Post: naughtyCat
  Getting largest indices of array less than or equal to an array of numbers schniefen 5 2,584 Nov-02-2020, 08:14 PM
Last Post: schniefen
  create new variable that sums the array prasanthbab1234 3 2,281 Sep-26-2020, 02:03 PM
Last Post: jefsummers
  Beginner: Exporting variable/array using OSC rkk16 4 2,363 May-27-2020, 01:08 PM
Last Post: rkk16
  3D array manipulation ibmr19 3 1,874 May-19-2020, 10:12 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020