Modify the data so that each individual slice is in a column of the 2d array. Then run the polyphyte once.
A2 = A.reshape(time_len, -1) regressions = np.polyfit(X, A2, degree) regressions = regressions.reshape(A.shape)
Or something like that ... I donβt quite understand that all sizes correspond to your data set, so Iβm not sure exactly what shape you want. But the fact is that each separate data set for polyfit should occupy a column in the matrix A2 .
By the way, if you are interested in performance, then you should profile your code using a profile module or something like that. Generally speaking, you cannot always predict how fast code will work just by looking at it. You must run it. Although in this case, deleting loops will also make your 100x code more readable, which is even more important.
cxrodgers
source share