Is there a way I could convert the xy_mean function to be computed using the pandas library just like the y_mean function. I found out that the pandas function Y_mean = pd.Series(PC_list).rolling(number).mean().dropna().to_numpy() is way faster than the numpy version ym = (np.convolve(PC_list, np.ones(shape=(number)), mode='valid')/number)[:-1]. The equation for the xy_mean would be ((index of value)*value + (index of value)*value)/number The index number would be dependent on the variable numbers value. So the first set of calculations for the example below would be (457.334015*1 + 424.440002*2 +394.795990*3)/number and the next set of numbers would be (424.440002*2 +394.795990*3 + 408.903992*4)/number and so on. If number = 4 Than the first set of calculations would be (457.334015*1 + 424.440002*2 +394.795990*3 +408.903992*4)/number. The set mean calculations would go on until the end of the PC_list array.
variables:
number = 3
PC_list= np.array([457.334015,424.440002,394.795990,408.903992,398.821014,402.152008,435.790985,423.204987,411.574005,
404.424988,399.519989,377.181000,375.467010,386.944000,383.614990,375.071991,359.511993,328.865997,
320.510010,330.079010,336.187012,352.940002,365.026001,361.562012,362.299011,378.549011,390.414001,
400.869995,394.773010,382.556000])
Vanilla python version:
y_mean = sum(PC_list[i:i+number])/number
xy_mean = sum([x * (i + 1) for i, x in enumerate(PC_list[i:i+number])])/number
Numpy versions:
y_mean = (np.convolve(PC_list, np.ones(shape=(number)), mode='valid')/number)[:-1]
xy_mean = (np.convolve(PC_list, np.arange(number, 0, -1), mode='valid'))[:-1]
Pandas version
Y_mean = pd.Series(PC_list).rolling(number).mean().dropna().to_numpy()
xy_mean = ?