'could not broadcast input array of shape (what I want) to (what I don't want)

I'm writing a code that reads data from monthly data (28, 29, 30 or 31 files in each month): we read the files and get a shape (31,24) array for each variable (9 variables total) Then we take the mean and standard deviation of the 31 rows and display them as written below, so that the resulting table has a shape (9,2,24).

    table9_2_24 = np.array([np.array([daymean1,daystdev1]),
     np.array([daymean2,daystdev2]),
     np.array([daymean3,daystdev3]),
     np.array([daymean4,daystdev4]),
     np.array([daymean5,daystdev5]),
     np.array([daymean6,daystdev6]),
     np.array([daymean7,daystdev7]),
     np.array([daymean8,daystdev8]),
     np.array([daymean9,daystdev9])])

This code worked without a problem for the January dataset, but then when I ran the exact same thing for the February dataset, I get the error:

could not broadcast input array from shape (2,24) into shape (2,)

which is tremendously infuriating as I don't even WANT the array to be broadcast into (2,), and in fact shape (2,24) was exactly what I wanted. Does anyone know how to resolve this?

Ps. using np.ndarray instead of np.array didn't work, I get :

only integer scalar arrays can be converted to a scalar index


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source